Ejemplo n.º 1
0
        public void ExportToExcel(DataTable resultTable, string fileLocation, string sheetName, string color = "", int numberOfLastRow = 0, int startingCellIndex = 1)
        {
            XLWorkbook   Workbook  = new XLWorkbook(fileLocation);
            IXLWorksheet Worksheet = Workbook.Worksheet(sheetName);

            //Gets the last used row
            if (numberOfLastRow == 0)
            {
                numberOfLastRow = Worksheet.LastRowUsed().RowNumber();
            }


            //Defines the starting cell for appeding  (Row , Column)
            IXLCell CellForNewData = Worksheet.Cell(numberOfLastRow + 1, startingCellIndex);

            if (!color.Equals(""))
            {
                for (int i = 0; i < resultTable.Rows.Count; i++)
                {
                    IXLRow RowForNewData = Worksheet.Row(numberOfLastRow + 1 + i);
                    RowForNewData.Style.Font.FontColor = XLColor.Red;
                }
            }
            //InsertData -  the data from the DataTable without the Column names ; InsertTable - inserts the data with the Column names
            CellForNewData.InsertData(resultTable);

            Workbook.SaveAs(fileLocation);
        }