| | |
| | | |
| | | public class ExcelExportSet |
| | | { |
| | | public List<string> Worksheets { get; set; } |
| | | public List<string> Worksheets { get; set; } = new List<string>(); |
| | | |
| | | /// <summary> |
| | | /// Key: Worksheet的名称 Value:Worksheet对应的列名集合(key 为要导出的列名 value 为导出后显示的列名) |
| | | /// </summary> |
| | | public Dictionary<string, Dictionary<string, string>> WorksheetColumns { get; set; } |
| | | public Dictionary<string, DataTable> WorksheetDataTable { get; set; } |
| | | public Dictionary<string, Dictionary<string, string>> WorksheetColumns { get; set; } = new Dictionary<string, Dictionary<string, string>>(); |
| | | |
| | | public ExcelExportSet() |
| | | { |
| | | Worksheets = new List<string>(); |
| | | WorksheetColumns = new Dictionary<string, Dictionary<string, string>>(); |
| | | WorksheetDataTable = new Dictionary<string, DataTable>(); |
| | | } |
| | | public Dictionary<string, Dictionary<string, string>> WorksheetRows { get; set; } = new Dictionary<string, Dictionary<string, string>>(); |
| | | |
| | | public Dictionary<string, DataTable> WorksheetDataTable { get; set; } = new Dictionary<string, DataTable>(); |
| | | |
| | | //public ExcelExportSet() |
| | | //{ |
| | | // Worksheets = new List<string>(); |
| | | // WorksheetColumns = new Dictionary<string, Dictionary<string, string>>(); |
| | | // WorksheetDataTable = new Dictionary<string, DataTable>(); |
| | | //} |
| | | |
| | | } |
| | | |
| | |
| | | { |
| | | // autofit width of cells with small content |
| | | ExcelRange columnCells = workSheet.Cells[workSheet.Dimension.Start.Row, columnIndex, workSheet.Dimension.End.Row, columnIndex]; |
| | | int maxLength = columnCells.Max(cell => cell.Value.ToString().Count()); |
| | | int maxLength = columnCells.Max(cell => (cell.Value ?? "").ToString().Count()); |
| | | if (maxLength < 150) |
| | | { |
| | | workSheet.Column(columnIndex).AutoFit(); |
| | |
| | | { |
| | | try |
| | | { |
| | | return obj.ToString(); |
| | | return (obj ?? "").ToString(); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |