0

我的排序条目在 excel 导出中混杂在一起。我想按日期再次对条目进行排序,或者如何防止值乱序?

我的出口代码:

 public static Byte[] ExportExcel(this DataTable dt, ExcelExportSetting setting)
        {
            byte[] exportData;

            using (ExcelPackage p = new ExcelPackage())
            {
                p.Workbook.Properties.Author = setting.Author;
                p.Workbook.Properties.Title = setting.Title;
                p.Workbook.Worksheets.Add(dt.TableName);
                ExcelWorksheet ws = p.Workbook.Worksheets[1];
                ws.Name = setting.WorksheetName; //Setting Sheet's name       
                ws.Cells.Style.Font.Size = setting.FontSize;    
                ws.Cells.Style.Font.Name = setting.FontName; sheet

                int colIndex = 1;
                int rowIndex = 1;

                foreach (DataColumn dc in dt.Columns) //Creating Headings
                {
                    var cell = ws.Cells[rowIndex, colIndex];
                    var font = cell.Style.Font;
                    font.Bold = true;
                    cell.Value = dc.Caption;
                    colIndex++;
                }    
                foreach (DataRow dr in dt.Rows) // Adding Data into rows
                {
                    colIndex = 1;
                    rowIndex++;
                    foreach (DataColumn dc in dt.Columns)
                    {
                        var cell = ws.Cells[rowIndex, colIndex];
                        cell.Value = dr[dc.ColumnName];                          
                        colIndex++;
                    }
                }
                exportData = p.GetAsByteArray();
            }
            return exportData;
        }
4

0 回答 0