//Data source DataTable
DataTable dataTable = new DataTable();
//...
//...
ExcelPackage package = new ExcelPackage();
//Create Sheet
ExcelWorksheet workSheet = package.Workbook.Worksheets.Add(Sheet1);
//Set cell data format
foreach (DataColumn item in dataTable.Columns)
{
if (item.DataType == typeof(DateTime))
{
var i = dataTable.Columns.IndexOf(item);
//Set the column format to custom "yyyy/MM/dd HH:mm:ss"
workSheet.Cells[2, i + 1, dataTable.Rows. Count + 1, i + 1].Style.Numberformat.Format = "yyyy/MM/dd HH:mm:ss";
}
}
//Set the first row and column heading style
using (ExcelRange r = workSheet.Cells[startRowFrom, 1, startRowFrom, dataTable.Columns.Count])
{
r.Style.Font.Color.SetColor(System.Drawing.Color.White);
r.Style.Font.Bold = true;
r.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
r.Style.Fill.BackgroundColor.SetColor(System.Drawing.ColorTranslator.FromHtml("#1fb5ad"));
}
//Set cell borders
using (ExcelRange r = workSheet.Cells[startRowFrom + 1, < span style="color: #800080;">1, startRowFrom + dataTable.Rows.Count, dataTable.Columns.Count])
{
r.Style.Border.Top.Style = ExcelBorderStyle.Thin;
r.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
r.Style.Border.Left.Style = ExcelBorderStyle.Thin;
r.Style.Border.Right.Style = ExcelBorderStyle.Thin;
r.Style.Border.Top.Color.SetColor(System.Drawing.Color.Black);
r.Style.Border.Bottom.Color.SetColor(System.Drawing.Color.Black);
r.Style.Border.Left.Color.SetColor(System.Drawing.Color.Black);
r.Style.Border.Right.Color.SetColor(System.Drawing.Color.Black);
}
//Load DataTable to Excel cell
workSheet.Cells["A1"].LoadFromDataTable(dataTable, true);
//output as bytes
byte[] result = package.GetAsByteArray();
return result;
//Data Source DataTable
DataTable dataTable = new DataTable();
//...
//...
ExcelPackage package = new ExcelPackage();
//Create Sheet
ExcelWorksheet workSheet = package.Workbook.Worksheets.Add(Sheet1);
//Set cell data format
foreach (DataColumn item in dataTable.Columns)
{
if (item.DataType == typeof(DateTime))
{
var i = dataTable.Columns.IndexOf(item);
//Set the column format to custom "yyyy/MM/dd HH:mm:ss"
workSheet.Cells[2, i + 1, dataTable.Rows. Count + 1, i + 1].Style.Numberformat.Format = "yyyy/MM/dd HH:mm:ss";
}
}
//Set the first row and column heading style
using (ExcelRange r = workSheet.Cells[startRowFrom, 1, startRowFrom, dataTable.Columns.Count])
{
r.Style.Font.Color.SetColor(System.Drawing.Color.White);
r.Style.Font.Bold = true;
r.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
r.Style.Fill.BackgroundColor.SetColor(System.Drawing.ColorTranslator.FromHtml("#1fb5ad"));
}
//Set cell borders
using (ExcelRange r = workSheet.Cells[startRowFrom + 1, < span style="color: #800080;">1, startRowFrom + dataTable.Rows.Count, dataTable.Columns.Count])
{
r.Style.Border.Top.Style = ExcelBorderStyle.Thin;
r.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
r.Style.Border.Left.Style = ExcelBorderStyle.Thin;
r.Style.Border.Right.Style = ExcelBorderStyle.Thin;
r.Style.Border.Top.Color.SetColor(System.Drawing.Color.Black);
r.Style.Border.Bottom.Color.SetColor(System.Drawing.Color.Black);
r.Style.Border.Left.Color.SetColor(System.Drawing.Color.Black);
r.Style.Border.Right.Color.SetColor(System.Drawing.Color.Black);
}
//Load DataTable to Excel cell
workSheet.Cells["A1"].LoadFromDataTable(dataTable, true);
//output as bytes
byte[] result = package.GetAsByteArray();
return result;
WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3027 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC