このコードはEPPlusから取得しても便利あなたの質問のため::
private void ExcelExport(DataTable table)
{
using (ExcelPackage packge = new ExcelPackage())
{
//Create the worksheet
ExcelWorksheet ws = packge.Workbook.Worksheets.Add("Demo");
//Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
ws.Cells["A1"].LoadFromDataTable(table, true);
//Format the header for column 1-3
using (ExcelRange range = ws.Cells["A1:C1"])
{
range.Style.Font.Bold = true;
range.Style.Fill.PatternType = ExcelFillStyle.Solid; //Set Pattern for the background to Solid
range.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(79, 129, 189)); //Set color to dark blue
range.Style.Font.Color.SetColor(Color.White);
}
//Example how to Format Column 1 as numeric
using (ExcelRange col = ws.Cells[2, 1, 2 + table.Rows.Count, 1])
{
col.Style.Numberformat.Format = "#,##0.00";
col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;
}
//Write it back to the client
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment; filename=ExcelExport.xlsx");
Response.BinaryWrite(packge.GetAsByteArray());
}
}
この質問に投票して悲しい、これは有効な質問です。将来他の人に役立つように私に投票をさせてください。 –
@AbhimanyuKumarVatsa、これは有効な質問ではありません。それはSOの話題ではありません。ここで受け入れ可能なことを理解するためにヘルプファイルを読むことをお勧めします。 –
@StephenMuecke私は2つの質問を見ていますが、話題はありません。私は新人が下投票だけでなく投稿を編集するべきだと感じています。または、彼に編集の機会を与えるためにいくつかのコメントを追加してください。私はまだ、本当のコミュニティの男が、無視しないことを示唆していると思います。 –