public static WritableSheet getExportSheet(WritableWorkbook workbook, String sheetName) { if (workbook == null || sheetName == null) { return null; } WritableSheet sheet = workbook.getSheet(sheetName); if (sheet == null) { sheet = workbook.createSheet(sheetName, workbook.getNumberOfSheets()); } return sheet; }
@SuppressWarnings("unchecked") public static void downLoad( List downList, String fileName, HttpServletResponse httpResponse, String downLoadId) { // 获取列对象集合 httpResponse.reset(); List columnList = new ArrayList(); try { // 初始化参数 DownloadBean downloadBean = DownloadContentHelper.getDownloadBean(downLoadId); columnList = downloadBean.getAttributes(); } catch (Exception e) { } OutputStream output = null; try { output = httpResponse.getOutputStream(); httpResponse.setContentType("application/vnd.ms-excel; charset=GBK"); httpResponse.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xls"); WritableWorkbook w = Workbook.createWorkbook(output); output.flush(); // 分sheet页操作start List<Object> newTotals = new ArrayList<Object>(); Iterator itTotals = downList.iterator(); while (itTotals.hasNext()) { newTotals.add(itTotals.next()); } int sheetNum = 0; while (newTotals.size() > MisConstants.MAXNUM_FOR_PER_SHEET) { WritableSheet ws = w.createSheet("Page" + (sheetNum + 1), sheetNum); addLabelExcel(ws, newTotals.subList(0, MisConstants.MAXNUM_FOR_PER_SHEET), columnList); newTotals.subList(0, MisConstants.MAXNUM_FOR_PER_SHEET).clear(); sheetNum = sheetNum + 1; } WritableSheet ws = w.createSheet("Page" + (sheetNum + 1), sheetNum); addLabelExcel(ws, newTotals, columnList); // 分sheet页操作end w.write(); // 关闭Excel工作薄对象 w.close(); if (output != null) output.close(); } catch (Exception e) { if (output != null) try { output.close(); } catch (IOException e1) { } e.printStackTrace(); } }
public File write() throws IOException, WriteException { File file = new File(path, "reports.xls"); WorkbookSettings wbSettings = new WorkbookSettings(); wbSettings.setLocale(new Locale("tr", "TR")); WritableWorkbook workbook = Workbook.createWorkbook(file, wbSettings); workbook.createSheet("Liste", 0); WritableSheet excelSheet = workbook.getSheet(0); createLabel(excelSheet); createContent(excelSheet); workbook.write(); workbook.close(); return file; }
public SingleNameReport(WritableWorkbook workbook, Statement new_statement, String[] arguments) { String main_tsn = ""; String main_rank = ""; String main_kingdom = ""; row = 0; try { statement = new_statement; func = new AdditionalFunctions(statement); copy = workbook; kingdom = arguments[0]; hrank = arguments[1]; lrank = arguments[2]; scientificName = arguments[3]; date_from = arguments[4]; date_to = arguments[5]; user = arguments[6]; String temp = ""; temp = "SELECT tsn,rank_id,kingdom_id from Tree where scientificName='" + scientificName + "'"; System.out.println(temp); result = statement.executeQuery(temp); metadata = result.getMetaData(); int numberOfRows = 0; int hrankVal = Integer.parseInt(hrank); int main_rankVal = 0; if (result.last()) numberOfRows = result.getRow(); result.first(); if (numberOfRows > 0 && metadata.getColumnCount() > 0) { main_tsn = result.getString(1); main_rank = result.getString(2); main_rankVal = Integer.parseInt(main_rank); main_kingdom = result.getString(3); } if (HasChildren(main_tsn) == true) FindChildInformation(main_tsn, arguments, func); FileInFrontPage frontPage = new FileInFrontPage(copy, statement, arguments); copy.write(); copy.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } // end of constructor
// public method to extract and write the Publication information public static void WritePublication(String publicationId, int rowNum) { WritableSheet sheet2 = copy.getSheet(1); try { String query = "SELECT address,author,publicationTitle,chapter,edition,editor,month,day,note,number,publisher," + "series,title,volume,year,isbn,issn,pages FROM Publication WHERE id=" + publicationId; System.out.println(query); ResultSet result_query = statement.executeQuery(query); ResultSetMetaData metadata_query = result_query.getMetaData(); int numberOfRows = 0; if (result_query.last()) numberOfRows = result_query.getRow(); result_query.first(); if (numberOfRows > 0 && metadata_query.getColumnCount() > 0) { String aut_edi = result_query.getString(2); System.out.println("autor is " + aut_edi); if (result_query.getString(6).compareTo("") != 0) aut_edi = aut_edi + " / " + result_query.getString(6) + ",eds."; Label label = new Label(7, rowNum, aut_edi); sheet2.addCell(label); label = new Label(8, rowNum, result_query.getString(13)); sheet2.addCell(label); String publication_name = result_query.getString(3); if (result_query.getString(12).compareTo("") != 0) publication_name = publication_name + ", ser. " + result_query.getString(12); if (result_query.getString(14).compareTo("0") != 0) publication_name = publication_name + ", vol. " + result_query.getString(14); if (result_query.getString(10).compareTo("0") != 0) publication_name = publication_name + ",no. " + result_query.getString(10); label = new Label(9, rowNum, publication_name); sheet2.addCell(label); label = new Label(12, rowNum, result_query.getString(11)); sheet2.addCell(label); label = new Label(13, rowNum, result_query.getString(1)); sheet2.addCell(label); label = new Label(15, rowNum, result_query.getString(9)); sheet2.addCell(label); label = new Label(16, rowNum, result_query.getString(16)); sheet2.addCell(label); label = new Label(17, rowNum, result_query.getString(17)); sheet2.addCell(label); label = new Label(14, rowNum, result_query.getString(18)); sheet2.addCell(label); String date = result_query.getString(15); String month = "Jan"; System.out.println("month is " + result_query.getString(7)); if (result_query.getString(7).compareTo("") != 0) month = result_query.getString(7); month = func.ConvertMonth(month); date = month + "/" + date; String day = "01"; if (result_query.getString(8).compareTo("0") != 0) day = result_query.getString(8); if (day.length() == 1) day = "0" + day; date = day + "/" + date; label = new Label(10, rowNum, date); sheet2.addCell(label); label = new Label(11, rowNum, date); sheet2.addCell(label); } } catch (Exception e) { e.printStackTrace(); System.exit(1); } } // end of WritePublication
// public method to find child information public void FindChildInformation(String tsn, String[] arguments, AdditionalFunctions func) { WritableSheet sheet2 = copy.getSheet(1); Label label = null; String children[] = null; String temp = "", current_tsn = "", dateCreated = ""; int dateCheck = 1; temp = "SELECT distinct tsn from Tree where parent_tsn='" + tsn + "'"; try { result = statement.executeQuery(temp); metadata = result.getMetaData(); int numberOfRows = 0; if (result.last()) numberOfRows = result.getRow(); if (numberOfRows > 0 && metadata.getColumnCount() > 0) { result.first(); children = new String[numberOfRows]; for (int j = 0; j < numberOfRows; j++) { children[j] = result.getString(1); result.next(); } } for (int j = 0; j < numberOfRows; j++) { int current_tsnId = Integer.parseInt(children[j]); if (current_tsnId >= 999000000) { temp = "SELECT distinct Tree.tsn,unit_name1,unit_name2,unit_name3,unit_name4,scientificName,`usage`," + "taxon_author,parent_tsn,rank_name, pages, publicationId, userId, dateCreated, nameType FROM Tree," + " BaseObject, TaxonConcepts, TaxonAuthors,TaxonUnitTypes" + " WHERE Tree.tsn=TaxonConcepts.tsn AND Tree.tsn='" + current_tsnId + "' AND " + "BaseObject.id=TaxonConcepts.id AND TaxonAuthors.taxon_author_id=Tree.taxon_author_id AND " + "Tree.rank_id=TaxonUnitTypes.rank_id"; System.out.println(temp); result = statement.executeQuery(temp); metadata = result.getMetaData(); int RowNumber = 0; if (result.last()) RowNumber = result.getRow(); if (RowNumber > 0 && metadata.getColumnCount() > 0) { current_tsn = result.getString(1); dateCreated = result.getString(14); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Date d1 = df.parse(dateCreated); Date d2 = null; if (date_from.compareTo("all") != 0) { d2 = df.parse(date_from); if (d2.before(d1) || d2.equals(d1)) dateCheck = 1; else dateCheck = 0; } if (date_to.compareTo("today") != 0) { d2 = df.parse(date_to); if (d1.before(d2) || d1.equals(d2)) dateCheck = 1; else dateCheck = 0; } if (result.getString(7).compareTo("public") == 0 && result.getString(15).compareTo("Regular scientific name") == 0 && result.getString(12).compareTo("") != 0 && dateCheck == 1) { String scientificName = result.getString(6); String taxon_author = result.getString(8); String publicationId = result.getString(12); for (int k = 0; k < 4; k++) { if (result.getString(k + 2).compareTo("null") != 0) { label = new Label(k, row + 1, result.getString(k + 2)); sheet2.addCell(label); } } label = new Label(4, row + 1, taxon_author); sheet2.addCell(label); label = new Label(5, row + 1, result.getString(10)); sheet2.addCell(label); String parent_tsn = result.getString(9); String userId = result.getString(13); WritePublication(publicationId, row + 1); label = new Label(18, row + 1, func.GetSubmitter(userId)); sheet2.addCell(label); label = new Label(6, row + 1, func.GetParent(parent_tsn)); sheet2.addCell(label); row = row + 1; } } } continue; } for (int j = 0; j < numberOfRows; j++) { if (HasChildren(children[j]) == true) FindChildInformation(children[j], arguments, func); else continue; } } catch (Exception e) { e.printStackTrace(); System.exit(1); } } // end of FindChildInformation
private void exportReport2Excel( ExportMaterialReportBean bean, ExportMaterialReportDTO results, HttpServletRequest request, HttpServletResponse response) { try { String outputFileName = "/files/temp/BaoCaoNhapXuatTonNPL" + System.currentTimeMillis() + ".xls"; String reportTemplate = request .getSession() .getServletContext() .getRealPath("/files/export/ExportMaterialReport.xls"); String export2FileName = request.getSession().getServletContext().getRealPath(outputFileName); Workbook templateWorkbook = Workbook.getWorkbook(new File(reportTemplate)); WritableWorkbook workbook = Workbook.createWorkbook(new File(export2FileName), templateWorkbook); WritableSheet sheet = workbook.getSheet(0); WritableFont normalFont = new WritableFont( WritableFont.TIMES, 12, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK); WritableCellFormat normalFormat = new WritableCellFormat(normalFont); normalFormat.setAlignment(Alignment.LEFT); normalFormat.setWrap(true); normalFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); WritableFont boldFont = new WritableFont( WritableFont.TIMES, 12, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK); WritableCellFormat headerFormat = new WritableCellFormat(boldFont); headerFormat.setAlignment(Alignment.CENTRE); headerFormat.setVerticalAlignment(VerticalAlignment.CENTRE); headerFormat.setWrap(true); headerFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); headerFormat.setBackground(jxl.format.Colour.GRAY_25); WritableCellFormat boldFormat = new WritableCellFormat(boldFont); boldFormat.setAlignment(Alignment.CENTRE); boldFormat.setWrap(true); boldFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); DecimalFormat decimalFormat = new DecimalFormat("###,###.##"); Date from = bean.getFromDate(); Label fromCell = new Label( 1, 1, from != null ? DateUtils.date2String(from, "dd/MM/yyyy") : "", boldFormat); sheet.addCell(fromCell); Date to = bean.getToDate(); Label toCell = new Label(1, 2, to != null ? DateUtils.date2String(to, "dd/MM/yyyy") : "", boldFormat); sheet.addCell(toCell); int startRow = 5; List<ExportMaterialReportDetailDTO> initialValue = results.getInitialValue(); Map<String, Double> mapImportValue = results.getMapImportValue(); Map<String, Double> mapExportUtilDateValue = results.getMapExportUtilDateValue(); Map<String, Double> mapExportDuringDateValue = results.getMapExportDuringDateValue(); int index; CellValue[] resValue; Double iVal; Double exportToVal; Double importVal; Double exportVal; Double remainVal; String key, origin; for (ExportMaterialReportDetailDTO initVal : initialValue) { origin = initVal.getOrigin() != null ? initVal.getOrigin().getOriginID().toString() : ""; key = initVal.getMaterial().getMaterialID() + "_" + origin; exportToVal = mapExportUtilDateValue.get(key) != null ? mapExportUtilDateValue.get(key) : 0d; iVal = initVal.getQuantity() != null ? initVal.getQuantity() - exportToVal : 0 - exportToVal; importVal = mapImportValue.get(key) != null ? mapImportValue.get(key) : 0d; exportVal = mapExportDuringDateValue.get(key) != null ? mapExportDuringDateValue.get(key) : 0d; remainVal = iVal + importVal - exportVal; index = 0; resValue = new CellValue[10]; resValue[index++] = new CellValue( CellDataType.STRING, initVal.getOrigin() != null ? initVal.getOrigin().getName() : ""); resValue[index++] = new CellValue( CellDataType.STRING, initVal.getMaterial() != null ? initVal.getMaterial().getName() : ""); resValue[index++] = new CellValue( CellDataType.STRING, StringUtils.isNotBlank(initVal.getCode()) ? initVal.getCode() : ""); resValue[index++] = new CellValue( CellDataType.STRING, initVal.getMaterial() != null ? initVal.getMaterial().getUnit() != null ? initVal.getMaterial().getUnit().getName() : "" : ""); resValue[index++] = new CellValue(CellDataType.STRING, decimalFormat.format(iVal)); resValue[index++] = new CellValue(CellDataType.STRING, decimalFormat.format(importVal)); resValue[index++] = new CellValue(CellDataType.STRING, decimalFormat.format(exportVal)); resValue[index++] = new CellValue(CellDataType.STRING, decimalFormat.format(remainVal)); resValue[index++] = new CellValue(CellDataType.STRING, ""); resValue[index++] = new CellValue( CellDataType.STRING, initVal.getImportDate() != null ? DateUtils.date2String(initVal.getImportDate(), "dd/MM/yyyy") : ""); ExcelUtil.addRow( sheet, startRow++, resValue, normalFormat, normalFormat, normalFormat, normalFormat); } workbook.write(); workbook.close(); response.sendRedirect( request.getSession().getServletContext().getContextPath() + outputFileName); } catch (Exception ex) { logger.error(ex.getMessage(), ex); } }
private void exportUsedMaterial2Excel( SearchUsedMaterialBean bean, SummaryUsedMaterialDTO result, HttpServletRequest request, HttpServletResponse response) { try { String outputFileName = "/files/temp/VatTuSuDung_" + System.currentTimeMillis() + ".xls"; String reportTemplate = request.getSession().getServletContext().getRealPath("/files/export/UsedMaterial.xls"); String export2FileName = request.getSession().getServletContext().getRealPath(outputFileName); Workbook templateWorkbook = Workbook.getWorkbook(new File(reportTemplate)); WritableWorkbook workbook = Workbook.createWorkbook(new File(export2FileName), templateWorkbook); WritableSheet sheet = workbook.getSheet(0); WritableFont normalFont = new WritableFont( WritableFont.TIMES, 12, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK); WritableCellFormat normalFormat = new WritableCellFormat(normalFont); normalFormat.setAlignment(Alignment.CENTRE); normalFormat.setWrap(true); normalFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); DecimalFormat decimalFormat = new DecimalFormat("###,###.##"); DecimalFormat decimalFormat2 = new DecimalFormat("###,###.####"); int startRow = 4; int stt = 1; List<UsedMaterialDTO> shareUsedMaterials = result.getShareUsedMaterials(); List<UsedMaterialDTO> usedProducts = result.getUsedProducts(); List<UsedMaterialDTO> usedMeasurementMaterials = result.getUsedMeasurementMaterials(); Double totalMainProductKg = 0d; Double totalMainProductMet2 = 0d; Integer counter = 0; Double totalMet2 = 0d; Double totalKg = 0d; Double kgMet; Double kgTan; Double materialUsed; if (usedProducts != null && usedProducts.size() > 0) { for (UsedMaterialDTO usedProduct : usedProducts) { totalKg = usedProduct.getTotalKgUsed(); totalMet2 = usedProduct.getTotalMUsed() * Integer.valueOf(usedProduct.getWidth()) / 1000; counter++; totalMainProductKg += totalKg; totalMainProductMet2 += totalMet2; addUsedMaterialRow( sheet, normalFormat, decimalFormat, decimalFormat2, startRow++, counter, usedProduct.getProductName().getName(), "Kg", totalKg, null, null); if (usedProduct.getUsedMaterialDTOs() != null && usedProduct.getUsedMaterialDTOs().size() > 0) { for (UsedMaterialDTO usedMaterial : usedProduct.getUsedMaterialDTOs()) { counter++; materialUsed = usedMaterial.getTotalUsed(); kgMet = totalMet2 > 0 ? materialUsed / totalMet2 : null; kgTan = totalKg > 0 ? materialUsed * 1000 / totalKg : null; addUsedMaterialRow( sheet, normalFormat, decimalFormat, decimalFormat2, startRow++, counter, usedMaterial.getMaterial().getName(), usedMaterial.getMaterial().getUnit().getName(), materialUsed, kgMet, kgTan); } } } } if (usedMeasurementMaterials != null && usedMeasurementMaterials.size() > 0) { for (UsedMaterialDTO usedMaterial : usedMeasurementMaterials) { counter++; materialUsed = usedMaterial.getTotalUsed(); kgMet = totalMet2 > 0 ? materialUsed / totalMainProductMet2 : null; kgTan = totalKg > 0 ? materialUsed * 1000 / totalMainProductKg : null; addUsedMaterialRow( sheet, normalFormat, decimalFormat, decimalFormat2, startRow++, counter, usedMaterial.getMaterial().getName(), usedMaterial.getMaterial().getUnit().getName(), materialUsed, kgMet, kgTan); } } if (shareUsedMaterials != null && shareUsedMaterials.size() > 0) { for (UsedMaterialDTO usedMaterial : shareUsedMaterials) { counter++; materialUsed = usedMaterial.getTotalUsed(); kgMet = totalMet2 > 0 ? materialUsed / totalMainProductMet2 : null; kgTan = totalKg > 0 ? materialUsed * 1000 / totalMainProductKg : null; addUsedMaterialRow( sheet, normalFormat, decimalFormat, decimalFormat2, startRow++, counter, usedMaterial.getMaterial().getName(), usedMaterial.getMaterial().getUnit().getName(), materialUsed, kgMet, kgTan); } } workbook.write(); workbook.close(); response.sendRedirect( request.getSession().getServletContext().getContextPath() + outputFileName); } catch (Exception ex) { logger.error(ex.getMessage(), ex); } }
public static void main(String args[]) { try { // 打开文件 WritableWorkbook book = Workbook.createWorkbook(new File("/home/uc/local/sandy/测试.xls")); // 生成名为“第一页”的工作表,参数0表示这是第一页 WritableSheet sheetOne = book.createSheet("第一页", 0); /** 定义单元格样式 */ WritableFont wf_title = new WritableFont( WritableFont.ARIAL, 11, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK); // 定义格式 字体 下划线 斜体 粗体 颜色 WritableFont wf_head = new WritableFont( WritableFont.ARIAL, 11, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK); // 定义格式 字体 下划线 斜体 粗体 颜色 WritableFont wf_table = new WritableFont( WritableFont.ARIAL, 11, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK); // 定义格式 字体 下划线 斜体 粗体 颜色 WritableCellFormat wcf_title = new WritableCellFormat(wf_title); // 单元格定义 wcf_title.setBackground(jxl.format.Colour.WHITE); // 设置单元格的背景颜色 wcf_title.setAlignment(jxl.format.Alignment.CENTRE); // 设置对齐方式 wcf_title.setBorder( jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN, jxl.format.Colour.BLACK); // 设置边框 WritableCellFormat wcf_title1 = new WritableCellFormat(wf_title); // 单元格定义 wcf_title1.setBackground(jxl.format.Colour.LIGHT_GREEN); // 设置单元格的背景颜色 wcf_title1.setAlignment(jxl.format.Alignment.CENTRE); // 设置对齐方式 wcf_title1.setBorder( jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN, jxl.format.Colour.BLACK); // 设置边框 WritableCellFormat wcf_title2 = new WritableCellFormat(wf_title); // 单元格定义 wcf_title2.setBackground(jxl.format.Colour.YELLOW2); // 设置单元格的背景颜色 wcf_title2.setAlignment(jxl.format.Alignment.CENTRE); // 设置对齐方式 wcf_title2.setBorder( jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN, jxl.format.Colour.BLACK); // 设置边框 WritableCellFormat wcf_head1 = new WritableCellFormat(wf_head); wcf_head1.setBackground(jxl.format.Colour.LIGHT_GREEN); wcf_head1.setAlignment(jxl.format.Alignment.CENTRE); wcf_head1.setBorder( jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN, jxl.format.Colour.BLACK); WritableCellFormat wcf_head2 = new WritableCellFormat(wf_head); wcf_head2.setBackground(jxl.format.Colour.YELLOW2); wcf_head2.setAlignment(jxl.format.Alignment.CENTRE); wcf_head2.setBorder( jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN, jxl.format.Colour.BLACK); WritableCellFormat wcf_table1 = new WritableCellFormat(wf_table); wcf_table1.setBackground(jxl.format.Colour.LIGHT_GREEN); wcf_table1.setAlignment(jxl.format.Alignment.CENTRE); wcf_table1.setBorder( jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN, jxl.format.Colour.BLACK); WritableCellFormat wcf_table2 = new WritableCellFormat(wf_table); wcf_table2.setBackground(jxl.format.Colour.YELLOW2); wcf_table2.setAlignment(jxl.format.Alignment.CENTRE); wcf_table2.setBorder( jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN, jxl.format.Colour.BLACK); sheetOne.setColumnView(0, 15); // 设置列的宽度 sheetOne.setColumnView(1, 15); // 设置列的宽度 sheetOne.setColumnView(2, 15); // 设置列的宽度 sheetOne.setColumnView(3, 15); // 设置列的宽度 sheetOne.setColumnView(4, 15); // 设置列的宽度 sheetOne.setColumnView(5, 15); // 设置列的宽度 sheetOne.setColumnView(6, 15); // 设置列的宽度 sheetOne.setColumnView(7, 15); // 设置列的宽度 sheetOne.setColumnView(8, 15); // 设置列的宽度 sheetOne.setColumnView(9, 15); // 设置列的宽度 sheetOne.setColumnView(10, 15); // 设置列的宽度 sheetOne.setColumnView(11, 15); // 设置列的宽度 sheetOne.setColumnView(12, 15); // 设置列的宽度 sheetOne.setColumnView(13, 15); // 设置列的宽度 // 在Label对象的构造子中指名单元格位置是第一列第一行(0,0) // 以及单元格内容为test Label title = new Label(0, 0, "统计", wcf_title); Label titleOne = new Label(0, 1, "统计1", wcf_title1); Label titleTwo = new Label(2, 1, "统计2", wcf_title2); Label column1 = new Label(0, 2, "姓名", wcf_head1); Label column2 = new Label(1, 2, "所选课程", wcf_head1); Label column3 = new Label(2, 2, "姓名", wcf_head2); Label column4 = new Label(3, 2, "所选课程", wcf_head2); // 或者WritableCell cell = new jxl.write.Number(column, row, value, wcf) // 将定义好的单元格添加到工作表中 sheetOne.addCell(title); sheetOne.addCell(titleOne); sheetOne.addCell(titleTwo); sheetOne.addCell(column1); sheetOne.addCell(column2); sheetOne.addCell(column3); sheetOne.addCell(column4); // 合: 第1列第1行 到 第13列第1行 sheetOne.mergeCells(0, 0, 3, 0); sheetOne.mergeCells(0, 1, 1, 1); sheetOne.mergeCells(2, 1, 3, 1); /*动态数据 */ Label content1 = new Label(0, 3, "张三", wcf_table1); Label content2 = new Label(0, 4, "张三", wcf_table1); Label content3 = new Label(0, 5, "张三", wcf_table1); Label kecheg1 = new Label(1, 3, "语文", wcf_table1); Label kecheg2 = new Label(1, 4, "数学", wcf_table1); Label kecheg3 = new Label(1, 5, "英语", wcf_table1); sheetOne.addCell(content1); sheetOne.addCell(content2); sheetOne.addCell(content3); sheetOne.addCell(kecheg1); sheetOne.addCell(kecheg2); sheetOne.addCell(kecheg3); sheetOne.mergeCells(0, 3, 0, 2 + 3); Label content11 = new Label(2, 3, "李四", wcf_table2); Label content22 = new Label(2, 4, "李四", wcf_table2); Label content33 = new Label(2, 5, "李四", wcf_table2); Label kecheg11 = new Label(3, 3, "语文", wcf_table2); Label kecheg22 = new Label(3, 4, "数学", wcf_table2); Label kecheg33 = new Label(3, 5, "英语", wcf_table2); sheetOne.addCell(content11); sheetOne.addCell(content22); sheetOne.addCell(content33); sheetOne.addCell(kecheg11); sheetOne.addCell(kecheg22); sheetOne.addCell(kecheg33); sheetOne.mergeCells(2, 3, 2, 2 + 3); // 写入数据并关闭文件 book.write(); book.close(); } catch (Exception e) { System.out.println(e); } }