/* * rowIndex and columnName act as the starting point for filling in data with Column headings. * In an excel prefilled with column names, rowIndex and columnName should still point to the first Column heading. * */ public static bool InsertPlainData(string connection, string query, string excelFilePath, string sheetName, string columnName, uint rowIndex, bool inlcudeHeadings = true) { bool success = true; try { using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Open(excelFilePath, true)) { var excelEditor = new ExcelEditor(spreadSheet, sheetName); DataTable dt = excelEditor.GetDataTable(query, connection); excelEditor.ExportDataTable(spreadSheet, columnName, rowIndex, dt, inlcudeHeadings); } } catch (Exception exception) { Debug.WriteLine(exception); success = false; } return(success); }
public static bool InsertDataTable(DataTable dt, Stream excelFile, string sheetName, string columnName, uint rowIndex, bool inlcudeHeadings = true) { bool success = true; try { using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Open(excelFile, true)) { var excelEditor = new ExcelEditor(spreadSheet, sheetName); if (excelEditor.SheetPrepared) { excelEditor.ExportDataTable(spreadSheet, columnName, rowIndex, dt, inlcudeHeadings); } } } catch (Exception e) { Debug.WriteLine(e.Message); success = false; } return(success); }