protected void SetListHead(ISheet sheet) { IRow row = sheet.CreateRow(this.HeadRowIndex); row.HeightInPoints = 25f; foreach (string str in this.defineLocation.Keys) { ICell cell = row.CreateCell(this.defineLocation[str]); cell.SetCellValue(str); cell.CellStyle = ExportCoreHelper.Getcellstyle(sheet.Workbook, StyleXls.头); } }
private void SetHeadStyles(string headName, MyColor color, StyleXls style) { if (!headStyles.ContainsKey(headName + color.ToString())) { IFont font; ICellStyle cellstyle = ExportCoreHelper.Getcellstyle(this.WorkBook, style); if (style == StyleXls.url) { font = ExportCoreHelper.GetFont(this.WorkBook, 2); } else if (style == StyleXls.头) { font = ExportCoreHelper.GetFont(this.WorkBook, 0); } else { font = ExportCoreHelper.GetFont(this.WorkBook, 1); } font.Color = ExportCoreHelper.GetColor(color); cellstyle.SetFont(font); headStyles.Add(headName + color.ToString(), cellstyle); } }
protected byte[] Export <T>(IList <T> DataSource, MyFileType fileType) { if ((fileType != MyFileType.EXCEL) && (fileType != MyFileType.EXCEL2003)) { throw new ExportException("不能导出类型" + fileType.ToString()); } int columnStartIndex = this.ColumnStartIndex; foreach (string str in this.Head) { this.defineLocation.Add(str, columnStartIndex); columnStartIndex++; } ExportHelper.headStyles = new Dictionary <string, ICellStyle>(); List <string> sheetName = new List <string>(); Dictionary <int, int> columnWidth = new Dictionary <int, int>(); BeginExportEventArgs e = new BeginExportEventArgs(sheetName, this.defineLocation, columnWidth); this.BeginExport(e); this.CurWorkBook = ExportCoreHelper.GetVersionWorkbook(fileType); ExportHelper.CellStyles = new Dictionary <StyleXls, ICellStyle>(); ExportHelper.CellStyles.Add(StyleXls.默认, ExportCoreHelper.Getcellstyle(CurWorkBook, StyleXls.默认)); ExportHelper.CellStyles.Add(StyleXls.时间, ExportCoreHelper.Getcellstyle(CurWorkBook, StyleXls.时间)); ExportHelper.CellStyles.Add(StyleXls.数字, ExportCoreHelper.Getcellstyle(CurWorkBook, StyleXls.数字)); if (this.RowStartIndex == 0) { this.RowStartIndex = this.HeadRowIndex + 1; } if (sheetName.Count == 0) { sheetName.Add("sheet1"); } using (MemoryStream stream = new MemoryStream()) { foreach (string str2 in sheetName) { ISheet sheet = this.CurWorkBook.CreateSheet(str2); foreach (string str3 in this.defineLocation.Keys) { int key = this.defineLocation[str3]; if (columnWidth.ContainsKey(key)) { sheet.SetColumnWidth(key, columnWidth[key] * 50); } else { int num3 = StringHelper.trueLength(str3); if (num3 > 14) { sheet.SetColumnWidth(key, 330 * num3); } else { sheet.SetColumnWidth(key, 0x1130); } } } this.SetListHead(sheet); this.SetListData(sheet); //AutoSizeColumns(sheet); } this.CurWorkBook.Write(stream); return(stream.ToArray()); } }