final excelFile = ex.Excel.createExcel();
final DateFormat monthFormat = DateFormat('MMMM yyyy');
final DateFormat dateFormat = DateFormat('dd MMM yyyy');
const headers = [
'Description', 'Price', 'Date', 'Type', 'Status', 'Number', 'Method'
];
//
// final defaultSheetName = excelFile.getDefaultSheet();
final yearlySheetName = 'Yearly_Summary_$year';
// if (defaultSheetName != null) {
// excelFile.rename(defaultSheetName, yearlySheetName);
// }
excelFile.rename('Sheet1', yearlySheetName);
excelFile.delete('Sheet1');
excelFile.unLink('Sheet1');
final yearlySheet = excelFile[yearlySheetName];
//
final titleCell = yearlySheet.cell(ex.CellIndex.indexByString("A1"));
titleCell.value = ex.TextCellValue("Yearly Summary $year");
//
final headerStyle = ex.CellStyle(
backgroundColorHex: ex.ExcelColor.teal,
fontFamily: ex.getFontFamily(ex.FontFamily.Calibri),
bold: true,
);
final boldStyle = ex.CellStyle(
bold: true,
fontFamily: ex.getFontFamily(ex.FontFamily.Calibri),
);
//
for (int i = 0; i < headers.length; i++) {
final cell = yearlySheet.cell(ex.CellIndex.indexByColumnRow(columnIndex: i, rowIndex: 1));
cell.value = ex.TextCellValue(headers);
cell.cellStyle = headerStyle;
}
//
final yearlyExpenses = await _databaseHelper.getYearlyExpenses(year);
double yearlyTotal = 0.0;
for (int i = 0; i < yearlyExpenses.length; i++) {
final exp = yearlyExpenses;
final row = i + 2;
yearlySheet.cell(ex.CellIndex.indexByColumnRow(columnIndex: 0, rowIndex: row)).value = ex.TextCellValue(exp.description);
yearlySheet.cell(ex.CellIndex.indexByColumnRow(columnIndex: 1, rowIndex: row)).value = ex.DoubleCellValue(exp.price);
yearlySheet.cell(ex.CellIndex.indexByColumnRow(columnIndex: 2, rowIndex: row)).value = ex.TextCellValue(dateFormat.format(exp.date));
yearlySheet.cell(ex.CellIndex.indexByColumnRow(columnIndex: 3, rowIndex: row)).value = ex.TextCellValue(exp.type);
yearlySheet.cell(ex.CellIndex.indexByColumnRow(columnIndex: 4, rowIndex: row)).value = ex.TextCellValue(exp.status);
yearlySheet.cell(ex.CellIndex.indexByColumnRow(columnIndex: 5, rowIndex: row)).value = ex.TextCellValue(exp.isRequired ? '1' : '2');
yearlySheet.cell(ex.CellIndex.indexByColumnRow(columnIndex: 6, rowIndex: row)).value = ex.TextCellValue(exp.method);
yearlyTotal += exp.price;
}
//
final totalRow = yearlyExpenses.length + 2;
yearlySheet.cell(ex.CellIndex.indexByColumnRow(columnIndex: 0, rowIndex: totalRow)).value = ex.TextCellValue("Total");
yearlySheet.cell(ex.CellIndex.indexByColumnRow(columnIndex: 0, rowIndex: totalRow)).cellStyle = boldStyle;
yearlySheet.cell(ex.CellIndex.indexByColumnRow(columnIndex: 1, rowIndex: totalRow)).value = ex.DoubleCellValue(yearlyTotal);
yearlySheet.cell(ex.CellIndex.indexByColumnRow(columnIndex: 1, rowIndex: totalRow)).cellStyle = boldStyle;
//
for (int month = 1; month
Подробнее здесь: https://stackoverflow.com/questions/797 ... sheets-row
Мобильная версия