我正在使用excel.dart包将数据保存在Excel中。
列的自动宽度设置存在问题。
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);
}