1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| public static void export_table_2_xls(HttpResponse Response, Table sourceTable, String sheetName)
{
// PrepareHeaders
{
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=resultat.xls");
Response.ContentType = "text/csv";
}
// Return .xls file in response
{
Workbook book = new Workbook();
WorksheetStyle style = book.Styles.Add("Entete");
style.Font.Bold = true;
style.Font.Color = "White";
style.Alignment.Horizontal = StyleHorizontalAlignment.Center;
style.Interior.Color = "Blue";
style.Interior.Pattern = StyleInteriorPattern.Solid;
Worksheet sheet = book.Worksheets.Add("Exemple");
WorksheetRow row = sheet.Table.Rows.Add();
row.Cells.Add(new WorksheetCell("Ventes par mois", DataType.String, "Entete") { MergeAcross = 5 });
row = sheet.Table.Rows.Add();
row.Cells.Add(new WorksheetCell("Commercial", DataType.String, "Entete"));
row.Cells.Add(new WorksheetCell("Janvier", DataType.String, "Entete"));
row.Cells.Add(new WorksheetCell("Février", DataType.String, "Entete"));
row.Cells.Add(new WorksheetCell("Mars", DataType.String, "Entete"));
row.Cells.Add(new WorksheetCell("Avril", DataType.String, "Entete"));
row.Cells.Add(new WorksheetCell("Total", DataType.String, "Entete"));
row = sheet.Table.Rows.Add();
row.Cells.Add(new WorksheetCell("Jean Dupont"));
row.Cells.Add(new WorksheetCell("5", DataType.Number));
row.Cells.Add(new WorksheetCell("8", DataType.Number));
row.Cells.Add(new WorksheetCell("6", DataType.Number));
row.Cells.Add(new WorksheetCell("10", DataType.Number));
row.Cells.Add(new WorksheetCell() { Formula = "=SUM(RC[-4]:RC[-1])" });
row = sheet.Table.Rows.Add();
row.Cells.Add(new WorksheetCell("Victor Hugo"));
row.Cells.Add(new WorksheetCell("54", DataType.Number));
row.Cells.Add(new WorksheetCell("26", DataType.Number));
row.Cells.Add(new WorksheetCell("34", DataType.Number));
row.Cells.Add(new WorksheetCell("75", DataType.Number));
row.Cells.Add(new WorksheetCell() { Formula = "=SUM(RC[-4]:RC[-1])" });
row = sheet.Table.Rows.Add();
row.Cells.Add(new WorksheetCell("Total", DataType.String, "Entete"));
row.Cells.Add(new WorksheetCell() { Formula = "=SUM(R[-2]C:R[-1]C)", StyleID = "Entete" });
row.Cells.Add(new WorksheetCell() { Formula = "=SUM(R[-2]C:R[-1]C)", StyleID = "Entete" });
row.Cells.Add(new WorksheetCell() { Formula = "=SUM(R[-2]C:R[-1]C)", StyleID = "Entete" });
row.Cells.Add(new WorksheetCell() { Formula = "=SUM(R[-2]C:R[-1]C)", StyleID = "Entete" });
row.Cells.Add(new WorksheetCell() { Formula = "=SUM(RC[-4]:RC[-1])", StyleID = "Entete" });
book.Save(Response.OutputStream);
}
} |
Partager