public void SaveDatabase(string database) { if (database == null) { Logger.WriteLog("Input value is null, SaveDatabase() ExcelSaver.", LogLevel.Error); return; } int tempRow = 0; string name = DateTime.Now.ToString() + ".xls"; string path = Directory.GetCurrentDirectory() + "/Saves/Excel/"; Directory.CreateDirectory(path); using (ExcelPackage excel = new ExcelPackage()) { ExcelWorksheet worksheet = excel.Workbook.Worksheets.Add("Worksheet1"); List <string> tables = clientSQL.ShowTables(); for (int i = 0; i < tables.Count; i++) { List <List <string> > tableData = new List <List <string> >(); List <string> columns = clientSQL.DescribeTable(tables[i]); for (int j = 0; j < columns.Count; j++) { List <string> columData = clientSQL.SelectColumTable(tables[i], columns[j]); tableData.Add(columData); } for (int j = 0; j < tableData.Count; j++) { for (int g = 0; g < tableData[j].Count; g++) { worksheet.Cells[g + tempRow + 1, j + 1].Value = tableData[j][g]; } } tempRow += tableData[0].Count; ++tempRow; worksheet.Cells[tempRow, 1].Value = ""; } FileInfo excelFile = new FileInfo(path + name); excel.SaveAs(excelFile); } }
public void SaveDatabase(string database) { string name = DateTime.Now.ToString(); string path = Directory.GetCurrentDirectory() + "/Saves/Word/"; Directory.CreateDirectory(path); DocX document = DocX.Create(path + name, DocumentTypes.Document); document.SaveAs(path + name + ".docx"); List <string> tables = clientSQL.ShowTables(); foreach (string table in tables) { List <List <string> > columsData = new List <List <string> >(); List <string> describeTable = clientSQL.DescribeTable(table); foreach (string describe in describeTable) { List <string> columData = clientSQL.SelectColumTable(table, describe); columsData.Add(columData); } Table docTable = document.AddTable(columsData[0].Count, describeTable.Count); docTable.Design = TableDesign.ColorfulListAccent1; docTable.Alignment = Alignment.center; for (int i = 0; i < columsData.Count - 1; i++) { docTable.SetColumnWidth(i, 1000); List <string> data = columsData[i]; for (int j = 0; j < data.Count - 1; j++) { docTable.Rows[j].Cells[i].Paragraphs[0].Append(data[j]); } } document.InsertTable(docTable); } document.Save(); }