/// <summary> /// 定义行列信息 /// </summary> /// <param name="rowCount"></param> /// <param name="colCount"></param> public I3ReportData(int rowCount, int colCount) { rows = new I3ReportRow[rowCount]; for (int i = 0; i < rows.Length; i++) //创建行 { rows[i] = new I3ReportRow(i, colCount); } cols = new I3ReportCol[colCount]; for (int j = 0; j < cols.Length; j++) //创建列 { cols[j] = new I3ReportCol(j); } }
private void exportAreaToSheet(I3PrintArea area, HSSFWorkbook workbook, ISheet sheet, ref int rowCount, Dictionary <string, HSSFCellStyle> styleDic, Dictionary <string, IFont> fontDic) { HSSFCellStyle emptyStyle = createEmptyStyle(workbook); //导出行、单元格 foreach (int rowIndex in area.AllRows) { //设置行高 rowCount++; IRow row = sheet.CreateRow(rowCount - 1); I3ReportRow rowData = area.ReportData.Rows[rowIndex]; if (rowData.PageBreak) //分页符 { sheet.SetRowBreak(rowCount - 1); } double dh = (double)rowData.Height * (double)15.305838; dh = dh * (double)1.1; int height = (int)Math.Ceiling(dh); row.Height = (short)height; //设置文本 int colIndex = -1; foreach (I3ReportCell cellData in rowData.Cells) { colIndex++; ICell cell = row.CreateCell(colIndex); bool hasReturnInText = false; if (cellData.MergState != I3MergeState.Merged) { hasReturnInText = !string.IsNullOrEmpty(cellData.Text) && cellData.Text.IndexOf("{r}") >= 0; if (cellData is I3ReportImageCell) { I3ReportImageCell imageCell = (I3ReportImageCell)cellData; byte[] bytes = imageCell.ImageData; if (bytes != null && bytes.Length > 0) { try { int pictureIdx = workbook.AddPicture(bytes, PictureType.JPEG); HSSFPatriarch patriarch = (HSSFPatriarch)sheet.CreateDrawingPatriarch(); // 插图片的位置 HSSFClientAnchor(dx1,dy1,dx2,dy2,col1,row1,col2,row2) 后面再作解释 int row1 = rowCount - 1; int row2 = rowCount - 1; int col1 = colIndex; int col2 = colIndex; if (cellData.MergState == I3MergeState.FirstCell) { I3MergeRange mr = area.ReportData.GetMergeRange(cellData.Row, cellData.Col); row2 = rowCount - 1 + mr.EndRow - mr.StartRow; col2 = mr.EndCol; } HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, col1, row1, col2, row2); //把图片插到相应的位置 HSSFPicture pict = (HSSFPicture)patriarch.CreatePicture(anchor, pictureIdx); } catch { } } } else { string text = string.IsNullOrEmpty(cellData.Text) ? "" : cellData.Text.Replace("{r}", "\r\n"); //特殊符号....使用替换符如{1级钢筋}{WL}{屈特比} cell.SetCellValue(text); } } //设置样式 int lastRowIndex = area.AllRows[area.AllRows.Length - 1]; bool isLastRow = rowData.Row == lastRowIndex; bool isLastCol = cellData.Col == area.ReportData.Cols.Length - 1; setCellStyle(workbook, sheet, cell, area, cellData, styleDic, fontDic, hasReturnInText, isLastRow, isLastCol, emptyStyle); //设置合并 if (cellData.MergState == I3MergeState.FirstCell) { I3MergeRange mr = area.ReportData.GetMergeRange(cellData.Row, cellData.Col); CellRangeAddress ra = new CellRangeAddress(rowCount - 1, rowCount - 1 + mr.EndRow - mr.StartRow, mr.StartCol, mr.EndCol); sheet.AddMergedRegion(ra); } } } }