public static Common.IncOpenExcel FillSomeData(IncOpenExcel myExcelFile, DataTable dataTable, string sheetName, List <int> columnsIndex, ref uint writtingRowNo, Common.IncOpenExcel.DefaultCellStyle defaultCellStyle) { if (myExcelFile != null && dataTable != null && sheetName != null && columnsIndex != null && columnsIndex.Count > 0) { //建立空表,填充对应字段值。create table DataTable totalTable = CreateTable(dataTable, columnsIndex); //得到样式,并fill report Dictionary <uint, uint> rowstyle = Common.IncOpenExcel.getRowStyles(totalTable.Columns, 2, 3, defaultCellStyle); for (int i = 0; i < rowstyle.Keys.Count; i++)//Total的样式特殊点,需要右边对齐,因为无法把total设置为数字类型,因为有'total'这个字符的存在,所以无法默认右边对齐.必须手工设置 { rowstyle[rowstyle.Keys.ToArray()[i]] = defaultCellStyle.normal_black_alignment; } myExcelFile.CreateOrUpdateRowAt(sheetName, totalTable.Rows[0], writtingRowNo, 2, rowstyle); writtingRowNo++; myExcelFile.CreateOrUpdateRowAt(sheetName, totalTable.Rows[1], writtingRowNo, 2, rowstyle); writtingRowNo++; } return(myExcelFile); }
private static bool CreateOrUpdateRowsAt(Common.IncOpenExcel excelFile, string sheetName, Common.IncOpenExcel.DefaultCellStyle defaultCellStyle, DataTable dataTable, uint rowNo, uint columnNo, Dictionary <uint, uint> titleStyle, bool titlehidden = false) { if (excelFile != null && sheetName != null && dataTable != null && defaultCellStyle != null) { DataTable columnsTable = Common.IncOpenExcel.GetColumnsNames(dataTable); if (titleStyle == null) { titleStyle = Common.IncOpenExcel.getRowStyles(columnsTable.Columns, columnNo, 3, defaultCellStyle);//3:black style } excelFile.CreateOrUpdateRowAt(sheetName, columnsTable.Rows[0], rowNo, columnNo, titleStyle, titlehidden); for (int i = 0; i < dataTable.Rows.Count; i++) { Dictionary <uint, uint> tempRowStyle = Common.IncOpenExcel.getRowStyles(dataTable.Columns, columnNo, 2, defaultCellStyle);//2:normal style excelFile.CreateOrUpdateRowAt(sheetName, dataTable.Rows[i], rowNo + (uint)(i + 1), columnNo, tempRowStyle); } } return(true); }