Future<void> setColumnAutoFit() async {
var excel = Excel.createExcel();
var sheet = excel[sheetName];
// Your logic to populate the Excel sheet goes here
// Set auto-fit for columns
for (var column in sheet.columns) {
var maxLength = 0;
for (var cell in column) {
if (cell.value.toString().length > maxLength) {
maxLength = cell.value.toString().length;
}
}
// Set column width based on the maximum cell value length
sheet.setColumnWidth(column.columnIndex, maxLength);
}
// Save the Excel file
await excel.save(fileName);
}
1条答案
按热度按时间qc6wkl3g1#
有同样的问题,然后通过询问Chatgpt找到了解决方案。