List of usage examples for org.apache.poi.hssf.usermodel HSSFCell setCellValue
@SuppressWarnings("fallthrough") public void setCellValue(boolean value)
From source file:com.eryansky.core.excelTools.JsGridReportBase.java
License:Apache License
/** * /*from w w w . ja v a2 s.c o m*/ * @param wb Excel * @param title Sheet?? * @param styles ? * @param creator * @param tableData ? * @throws Exception */ public HSSFWorkbook writeSheet(HSSFWorkbook wb, String title, HashMap<String, HSSFCellStyle> styles, String creator, TableData tableData) throws Exception { SimpleDateFormat formater = new SimpleDateFormat("yyyyMMdd HHmm"); String create_time = formater.format(new Date()); HSSFSheet sheet = wb.createSheet(title);// Excel sheet.setDisplayGridlines(false);// ? HSSFRow row = sheet.createRow(0);// HSSFCell cell = row.createCell(0);// int rownum = 0; cell.setCellValue(new HSSFRichTextString(title)); HSSFCellStyle style = styles.get("TITLE"); if (style != null) cell.setCellStyle(style); TableHeaderMetaData headerMetaData = tableData.getTableHeader();// HTML sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headerMetaData.getColumnCount() - 1)); row = sheet.createRow(1); cell = row.createCell(0); cell.setCellValue(new HSSFRichTextString(":")); style = styles.get("SUB_TITLE"); if (style != null) cell.setCellStyle(style); cell = row.createCell(1); cell.setCellValue(new HSSFRichTextString(creator)); style = styles.get("SUB_TITLE2"); if (style != null) cell.setCellStyle(style); cell = row.createCell(2); cell.setCellValue(new HSSFRichTextString(":")); style = styles.get("SUB_TITLE"); if (style != null) cell.setCellStyle(style); cell = row.createCell(3); style = styles.get("SUB_TITLE2"); cell.setCellValue(new HSSFRichTextString(create_time)); if (style != null) cell.setCellStyle(style); rownum = 3;// rownum = 1? HSSFCellStyle headerstyle = styles.get("TABLE_HEADER"); System.out.println(JsonMapper.getInstance().toJson(headerMetaData)); int colnum = 0; for (int i = 0; i < headerMetaData.getOriginColumns().size(); i++) { TableColumn tc = headerMetaData.getOriginColumns().get(i); if (i != 0) { colnum += headerMetaData.getOriginColumns().get(i - 1).getLength(); } generateColumn(sheet, tc, headerMetaData.maxlevel, rownum, colnum, headerstyle); } rownum += headerMetaData.maxlevel; List<TableDataRow> dataRows = tableData.getRows(); HashMap<Integer, Integer> counter = new HashMap<Integer, Integer>(); HashMap<Integer, String> word = new HashMap<Integer, String>(); int index = 0; for (TableDataRow dataRow : dataRows) { row = sheet.createRow(rownum); List<TableDataCell> dataCells = dataRow.getCells(); int size = headerMetaData.getColumns().size(); index = -1; for (int i = 0; i < size; i++) { TableColumn tc = headerMetaData.getColumns().get(i); if (!tc.isVisible()) continue; index++; String value = dataCells.get(i).getValue(); if (tc.isGrouped()) { String w = word.get(index); if (w == null) { word.put(index, value); counter.put(index, 1); createCell(row, tc, dataCells, i, index, styles); } else { if (w.equals(value)) { counter.put(index, counter.get(index) + 1); } else { stopGrouping(sheet, word, counter, index, size, rownum, styles.get("STRING")); word.put(index, value); counter.put(index, 1); createCell(row, tc, dataCells, i, index, styles); } } } else { createCell(row, tc, dataCells, i, index, styles); } } rownum++; } stopGrouping(sheet, word, counter, 0, index, rownum, styles.get("STRING")); // ??? for (int c = 0; c < headerMetaData.getColumns().size(); c++) { sheet.autoSizeColumn((short) c, true); } sheet.setGridsPrinted(true); return wb; }
From source file:com.eryansky.core.excelTools.JsGridReportBase.java
License:Apache License
/** * ?/*from w w w . j a v a 2 s . c o m*/ * * @param * @return void */ private void createCell(HSSFRow row, TableColumn tc, List<TableDataCell> data, int i, int index, HashMap<String, HSSFCellStyle> styles) { TableDataCell dc = data.get(i); HSSFCell cell = row.createCell(index); switch (tc.getColumnType()) { case TableColumn.COLUMN_TYPE_INTEGER: cell.setCellValue(dc.getIntValue()); HSSFCellStyle style = styles.get("INT"); if (row.getRowNum() % 2 != 0) style = styles.get("INT_C"); if (style != null) cell.setCellStyle(style); break; case TableColumn.COLUMN_TYPE_FLOAT_2: cell.setCellValue(dc.getDoubleValue()); style = styles.get("D2"); if (row.getRowNum() % 2 != 0) style = styles.get("D2_C"); if (style != null) cell.setCellStyle(style); break; case TableColumn.COLUMN_TYPE_FLOAT_3: cell.setCellValue(dc.getDoubleValue()); style = styles.get("D3"); if (row.getRowNum() % 2 != 0) style = styles.get("D3_C"); if (style != null) cell.setCellStyle(style); break; case TableColumn.COLUMN_TYPE_RED_BG: cell.setCellValue(dc.getValue()); style = styles.get("RED_BG"); if (style != null) cell.setCellStyle(style); break; case TableColumn.COLUMN_TYPE_YELLOW_BG: cell.setCellValue(dc.getValue()); style = styles.get("YELLOW_BG"); if (style != null) cell.setCellStyle(style); break; case TableColumn.COLUMN_TYPE_GREEN_BG: cell.setCellValue(dc.getValue()); style = styles.get("GREEN_BG"); if (style != null) cell.setCellStyle(style); break; default: if (dc.getValue().equalsIgnoreCase(" ")) cell.setCellValue(""); else cell.setCellValue(dc.getValue()); style = styles.get("STRING"); if (row.getRowNum() % 2 != 0) style = styles.get("STRING_C"); if (style != null) cell.setCellStyle(style); } }
From source file:com.esd.cs.common.PoiCreateExcel.java
License:Open Source License
/** * ?/*ww w.j a v a 2 s .co m*/ * * @param FilePath * @param workerList * @return */ public static boolean createExcel(String FilePath, List<WorkerTemp> workerList) { // Excel Workbook,excel HSSFWorkbook wb = new HSSFWorkbook(); // Excelsheet,exceltab HSSFSheet sheet = wb.createSheet("sheet1"); // excel? sheet.setColumnWidth(0, 4000); sheet.setColumnWidth(1, 3500); // Excel? HSSFRow headRow = sheet.createRow(0); HSSFCell headell = headRow.createCell(0); // ??? headell = headRow.createCell(0); headell.setCellValue("??"); headell = headRow.createCell(1); headell.setCellValue("??"); sheet.setColumnWidth(1, 8000); headell = headRow.createCell(2); headell.setCellValue(""); sheet.setColumnWidth(2, 13000); for (int i = 1; i <= workerList.size(); i++) { WorkerTemp worker = workerList.get(i - 1); // Excel? HSSFRow row = sheet.createRow(i); HSSFCell cell = row.createCell(0); // ??? cell = row.createCell(0); cell.setCellValue(worker.getWorkerName()); cell = row.createCell(1); cell.setCellValue(worker.getWorkerHandicapCode()); cell = row.createCell(2); cell.setCellValue(worker.getRemark()); } try { FileOutputStream os = new FileOutputStream(FilePath); wb.write(os); os.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return true; }
From source file:com.esd.cs.common.PoiCreateExcel.java
License:Open Source License
/** * ???//from w ww . j a v a 2s . co m * * @param FilePath * @param companyList * @return */ public static boolean createComapnyExcel(String FilePath, List<Company> companyList) { // Excel Workbook,excel HSSFWorkbook wb = new HSSFWorkbook(); // Excelsheet,exceltab HSSFSheet sheet = wb.createSheet("sheet1"); // excel? sheet.setColumnWidth(0, 4000); sheet.setColumnWidth(1, 3500); // Excel? HSSFRow headRow = sheet.createRow(0); HSSFCell headell = headRow.createCell(0); // ??? headell = headRow.createCell(0); headell.setCellValue("?"); headell = headRow.createCell(1); headell.setCellValue("?"); headell = headRow.createCell(2); headell.setCellValue("????"); sheet.setColumnWidth(2, 12000); // headell = headRow.createCell(3); headell.setCellValue(""); headell = headRow.createCell(4); headell.setCellValue("?"); headell = headRow.createCell(5); headell.setCellValue("???"); headell = headRow.createCell(6); headell.setCellValue("??"); headell = headRow.createCell(7); headell.setCellValue(""); headell = headRow.createCell(8); headell.setCellValue("???"); sheet.setColumnWidth(8, 12000); for (int i = 1; i <= companyList.size(); i++) { Company company = companyList.get(i - 1); // Excel? HSSFRow row = sheet.createRow(i); HSSFCell cell = row.createCell(0); // ??? // ? cell = row.createCell(0); cell.setCellValue(company.getCompanyCode()); // ? cell = row.createCell(1); cell.setCellValue(company.getCompanyTaxCode()); // ??? cell = row.createCell(2); cell.setCellValue(company.getCompanyName()); // cell = row.createCell(3); cell.setCellValue(company.getCompanyLegal()); // ? cell = row.createCell(4); cell.setCellValue(company.getCompanyContactPerson()); // ??? cell = row.createCell(5); cell.setCellValue(company.getCompanyPhone()); // ?? cell = row.createCell(6); cell.setCellValue(company.getCompanyMobile()); // cell = row.createCell(7); cell.setCellValue(company.getCompanyZipCode()); // ??? cell = row.createCell(8); cell.setCellValue(company.getCompanyAddress()); } try { FileOutputStream os = new FileOutputStream(FilePath); wb.write(os); os.flush(); os.close(); companyList.clear(); companyList = null; os = null; wb = null; System.gc(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return true; }
From source file:com.esd.cs.common.PoiCreateExcel.java
License:Open Source License
/** * // w ww. j ava2 s . c o m * * @param FilePath * @param companyList * @return */ public static boolean createRepeaExcel(String FilePath, List<ReportViewModel> companyList, ReportModel model) { // Excel Workbook,excel HSSFWorkbook wb = new HSSFWorkbook(); // Excelsheet,exceltab HSSFSheet sheet = wb.createSheet("sheet1"); // excel? sheet.setColumnWidth(0, 4000); sheet.setColumnWidth(1, 3500); // Excel? HSSFRow headRow0 = sheet.createRow(0); HSSFCell headCell = headRow0.createCell(0); // ?? sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 13));// ??? headCell = headRow0.createCell(0); // headCell.setCellValue(model.getTitle()); // ? HSSFCellStyle style = wb.createCellStyle(); style.setFillBackgroundColor(HSSFColor.GREEN.index); style.setAlignment(CellStyle.ALIGN_CENTER);// style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);// // HSSFFont font = wb.createFont(); font.setFontHeightInPoints((short) 12); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // style.setFont(font); headCell.setCellStyle(style); // ? ?? HSSFRow RowTow = sheet.createRow(1); HSSFCell CellTow = headRow0.createCell(1); // ?? sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 5));// ??? CellTow = RowTow.createCell(0); // CellTow.setCellValue(model.getCreateCompany()); // ? // ?? sheet.addMergedRegion(new CellRangeAddress(1, 1, 6, 13));// ??? CellTow = RowTow.createCell(6); HSSFCellStyle style1 = wb.createCellStyle(); style1.setFillBackgroundColor(HSSFColor.GREEN.index); style1.setAlignment(CellStyle.ALIGN_RIGHT);// ? CellTow.setCellStyle(style1); // CellTow.setCellValue(model.getCreateData()); // ? HSSFRow headRow = sheet.createRow(2); HSSFCell headell = headRow.createCell(2); // ??? headell = headRow.createCell(0); headell.setCellValue(model.getType()); headell = headRow.createCell(1); headell.setCellValue("??"); headell = headRow.createCell(2); headell.setCellValue("??"); sheet.setColumnWidth(2, 3000); // headell = headRow.createCell(3); headell.setCellValue("???"); sheet.setColumnWidth(3, 3000); // headell = headRow.createCell(4); headell.setCellValue("???"); sheet.setColumnWidth(4, 4000); // headell = headRow.createCell(5); headell.setCellValue("???"); sheet.setColumnWidth(5, 4000); // headell = headRow.createCell(6); headell.setCellValue("???"); sheet.setColumnWidth(6, 4500); // headell = headRow.createCell(7); headell.setCellValue(""); sheet.setColumnWidth(8, 4000); headell = headRow.createCell(8); headell.setCellValue(""); sheet.setColumnWidth(8, 4000); headell = headRow.createCell(9); headell.setCellValue(""); sheet.setColumnWidth(9, 4000); headell = headRow.createCell(10); headell.setCellValue("?"); sheet.setColumnWidth(10, 4000); headell = headRow.createCell(11); headell.setCellValue("???"); headell = headRow.createCell(12); headell.setCellValue("?"); headell = headRow.createCell(13); headell.setCellValue("?"); for (int i = 0; i < companyList.size(); i++) { ReportViewModel company = companyList.get(i); // Excel? HSSFRow row = sheet.createRow(i + 3); HSSFCell cell = row.createCell(i + 3); // ??? // ???? cell = row.createCell(0); cell.setCellValue(company.getReportName()); // ?? cell = row.createCell(1); cell.setCellValue(company.getUnitNum()); // ?? cell = row.createCell(2); cell.setCellValue(company.getEmpTotal()); // ??? cell = row.createCell(3); cell.setCellValue(company.getUnAudit()); // ?, ??? cell = row.createCell(4); cell.setCellValue(company.getUnReAudit()); // ?, ?? cell = row.createCell(5); cell.setCellValue(company.getAuditOk()); // ?, ?? cell = row.createCell(6); cell.setCellValue(company.getUnauditOk()); // cell = row.createCell(7); cell.setCellValue(company.getShouldTotal().toString()); // ? cell = row.createCell(8); cell.setCellValue(company.getAlreadyTotal().toString()); // cell = row.createCell(9); cell.setCellValue(company.getLessTotal().toString()); // ? cell = row.createCell(10); cell.setCellValue(company.getAmountPayable().toString()); // ??? cell = row.createCell(11); cell.setCellValue(company.getReductionAmount().toString()); // ? cell = row.createCell(12); cell.setCellValue(company.getActualAmount().toString()); // ? cell = row.createCell(13); cell.setCellValue(company.getAlreadyAmount().toString()); } // ? HSSFRow row = sheet.createRow(companyList.size() + 3); HSSFCell cell = row.createCell(companyList.size() + 3); // ??? // ???? sheet.addMergedRegion(new CellRangeAddress(companyList.size() + 3, companyList.size() + 3, 0, 13));// ??? cell = row.createCell(0); // ? HSSFCellStyle styleFoot = wb.createCellStyle(); styleFoot.setAlignment(CellStyle.ALIGN_RIGHT);// ? cell.setCellStyle(styleFoot); // cell.setCellValue(model.getCreatePeople()); try { FileOutputStream os = new FileOutputStream(FilePath); wb.write(os); os.flush(); os.close(); companyList.clear(); companyList = null; os = null; wb = null; System.gc(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return true; }
From source file:com.esd.ps.excel.PoiCreateExcel.java
License:Open Source License
/** * ?/*from w w w . j a va2s.c o m*/ * * @param FilePath * @param companyList * @return */ public static boolean createRegistrationExcel(String FilePath, List<Registration> list) { // Excel Workbook,excel HSSFWorkbook wb = new HSSFWorkbook(); // Excelsheet,exceltab HSSFSheet sheet = wb.createSheet("sheet1"); // excel? sheet.setColumnWidth(0, 4000); sheet.setColumnWidth(1, 3500); // Excel? HSSFRow headRow = sheet.createRow(0); HSSFCell headell = headRow.createCell(0); // ??? headell = headRow.createCell(0); headell.setCellValue("??"); headell = headRow.createCell(1); headell.setCellValue("??"); headell = headRow.createCell(2); headell.setCellValue("??"); // sheet.setColumnWidth(2, 12000); // headell = headRow.createCell(3); headell.setCellValue("QQ"); headell = headRow.createCell(4); headell.setCellValue("??"); headell = headRow.createCell(5); headell.setCellValue("??"); SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATETIME_FORMAT); for (int i = 1; i <= list.size(); i++) { Registration r = list.get(i - 1); // Excel? HSSFRow row = sheet.createRow(i); HSSFCell cell = row.createCell(0); // ??? // ?? cell = row.createCell(0); cell.setCellValue(r.getName()); // ?? cell = row.createCell(1); cell.setCellValue(r.getCard()); // ? cell = row.createCell(2); cell.setCellValue(r.getPhone()); // QQ cell = row.createCell(3); cell.setCellValue(r.getQq()); // ?? cell = row.createCell(4); cell.setCellValue(r.getAddress()); // ?? cell = row.createCell(5); cell.setCellValue(sdf.format(r.getCreateTime())); } try { FileOutputStream os = new FileOutputStream(FilePath); wb.write(os); os.flush(); os.close(); list.clear(); list = null; os = null; wb = null; System.gc(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return true; }
From source file:com.frameworkset.platform.sanylog.util.POIExcelUtil.java
License:Open Source License
/** * Excel Workbook?.//from www . j av a 2 s. c om * * @param colDesc 17"?:user_id,??:user_name,:type_name" * @param dataList * @return * @author gw_liaozh * @throws InvocationTargetException * @throws IllegalAccessException * @throws IllegalArgumentException */ public static HSSFWorkbook createHSSFWorkbook(String colDesc, List<?> dataList) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { //???17 //TODO: ? List<String> colTitleList = getColumnTitleList(colDesc); List<String> colFieldList = getColumnFieldList(colDesc); HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(); HSSFFont font = getBaseFont(wb); HSSFCellStyle headCellStyle = getHeadCellStyle(wb, font); //? CellStyle dateCellStyle = getDateTimeCellStyle(wb); //CellStyle strCellStyle = getStringCellStyle(wb); //??17 HSSFDataValidationHelper dvHelper = new HSSFDataValidationHelper(sheet); Map<String, Class<?>> fieldTypeMap = new HashMap<String, Class<?>>(); // HSSFRow titleRow = sheet.createRow(0); for (int i = 0; i < colTitleList.size(); i++) { HSSFCell cell = titleRow.createCell(i); cell.setCellStyle(headCellStyle); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(colTitleList.get(i)); } //?17 for (int i = 0; i < dataList.size(); i++) { Object obj = dataList.get(i); HSSFRow row = sheet.createRow(i + 1); for (int j = 0; j < colFieldList.size(); j++) { String fieldName = colFieldList.get(j); HSSFCell cell = row.createCell(j); if (obj == null) { continue; } Object value = BeanConvertUtil.getProperty(obj, fieldName); //ClassInfo classInfo = ClassUtil.getClassInfo(obj.getClass()); //Object value = classInfo.getPropertyDescriptor(fieldName).getValue(obj); if (value == null) { continue; } //?? if (value instanceof Number) { cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(((Number) value).doubleValue()); } else if (value instanceof Date) { cell.setCellStyle(dateCellStyle); cell.setCellValue((Date) value); } else { cell.setCellType(HSSFCell.CELL_TYPE_STRING); //cell.setCellStyle(strCellStyle); cell.setCellValue(value.toString()); } fieldTypeMap.put(fieldName, value.getClass()); } } //?? for (int i = 0; i < colFieldList.size(); i++) { String fieldName = colFieldList.get(i); Class<?> fieldClass = fieldTypeMap.get(fieldName); if (fieldClass == null) { continue; } CellRangeAddressList range = new CellRangeAddressList(1, 65535, i, i); DataValidationConstraint constraint = null; if (Integer.class.isAssignableFrom(fieldClass)) { constraint = dvHelper.createIntegerConstraint(DataValidationConstraint.OperatorType.NOT_BETWEEN, "0", "-1"); sheet.addValidationData(dvHelper.createValidation(constraint, range)); } else if (Number.class.isAssignableFrom(fieldClass)) { constraint = dvHelper.createNumericConstraint(DataValidationConstraint.ValidationType.DECIMAL, DataValidationConstraint.OperatorType.NOT_BETWEEN, "0", "-1"); sheet.addValidationData(dvHelper.createValidation(constraint, range)); } else if (Date.class.isAssignableFrom(fieldClass)) { constraint = dvHelper.createDateConstraint(DataValidationConstraint.OperatorType.NOT_BETWEEN, "0000-01-02", "0000-01-01", "yyyy-MM-dd"); sheet.addValidationData(dvHelper.createValidation(constraint, range)); } } // for (int i = 0; i < colTitleList.size(); i++) { //?? //sheet.autoSizeColumn(i); } return wb; }
From source file:com.github.dougkelly88.FLIMPlateReaderGUI.SequencingClasses.Classes.FilterTableModel.java
public void saveFilterTableModelAsSpreadsheet() { // Save FilterTable in second sheet of wb .xls // Initialize second sheet HSSFSheet sheet2 = HCAFLIMPluginFrame.wb.createSheet("SpectralSequencing"); // Initialize first row with headers int RowSize = data_.size(); HSSFRow row0 = sheet2.createRow(0);// w w w .j av a 2 s . co m HSSFCell cell00 = row0.createCell(0); HSSFCell cell01 = row0.createCell(1); HSSFCell cell02 = row0.createCell(2); HSSFCell cell03 = row0.createCell(3); HSSFCell cell04 = row0.createCell(4); HSSFCell cell05 = row0.createCell(5); HSSFCell cell06 = row0.createCell(6); HSSFCell cell07 = row0.createCell(7); cell00.setCellValue("Label"); cell01.setCellValue("Ex filter"); cell02.setCellValue("ND filter"); cell03.setCellValue("Dichroic"); cell04.setCellValue("Em filter"); cell05.setCellValue("Filter Cube"); cell06.setCellValue("Camera integration (ms)"); cell07.setCellValue("Delays"); // write row for row from table to .xls for (int RowNum = 0; RowNum < RowSize; RowNum++) { HSSFRow row = sheet2.createRow(RowNum + 1); HSSFCell cell0 = row.createCell(0); HSSFCell cell1 = row.createCell(1); HSSFCell cell2 = row.createCell(2); HSSFCell cell3 = row.createCell(3); HSSFCell cell4 = row.createCell(4); HSSFCell cell5 = row.createCell(5); HSSFCell cell6 = row.createCell(6); HSSFCell cell7 = row.createCell(7); cell0.setCellValue(data_.get(RowNum).getLabel()); cell1.setCellValue(data_.get(RowNum).getExFilt()); cell2.setCellValue(data_.get(RowNum).getNDFilt()); cell3.setCellValue(data_.get(RowNum).getDiFilt()); cell4.setCellValue(data_.get(RowNum).getEmFilt()); cell5.setCellValue(data_.get(RowNum).getCube()); cell6.setCellValue(data_.get(RowNum).getIntTime()); // convert Array<List> to String like "[0, 1000, 2000, 3000]" and write it to .xls ArrayList<Integer> a = new ArrayList<Integer>(); a = data_.get(RowNum).getDelays(); List<String> newList = new ArrayList<String>(a.size()); for (Integer myInt : a) { newList.add(String.valueOf(myInt)); } String b = "["; for (String s : newList) { b += s + ", "; } int s = b.length(); b = b.substring(0, s - 2); b = b + "]"; cell7.setCellValue(b); } }
From source file:com.github.dougkelly88.FLIMPlateReaderGUI.SequencingClasses.Classes.FOVTableModel.java
public void saveFOVTableModelAsSpreadsheet() { // Save FilterTable in first sheet of wb .xls // Initialize first sheet HSSFSheet sheet1 = HCAFLIMPluginFrame.wb.createSheet("XYSequencing"); // Initialize first row with headers int RowSize = data_.size(); HSSFRow row0 = sheet1.createRow(0);// w ww .j a v a 2s . c om HSSFCell cell00 = row0.createCell(0); HSSFCell cell01 = row0.createCell(1); HSSFCell cell02 = row0.createCell(2); HSSFCell cell03 = row0.createCell(3); HSSFCell cell04 = row0.createCell(4); cell00.setCellValue("Well"); cell01.setCellValue("X " + um); cell02.setCellValue("Y" + um); cell03.setCellValue("Z" + um); cell04.setCellValue("Group"); // write row for row from table to sheet for (int RowNum = 0; RowNum < RowSize; RowNum++) { HSSFRow row = sheet1.createRow(RowNum + 1); HSSFCell cell0 = row.createCell(0); HSSFCell cell1 = row.createCell(1); HSSFCell cell2 = row.createCell(2); HSSFCell cell3 = row.createCell(3); HSSFCell cell4 = row.createCell(4); cell0.setCellValue(data_.get(RowNum).getWell()); cell1.setCellValue(data_.get(RowNum).getX()); cell2.setCellValue(data_.get(RowNum).getY()); cell3.setCellValue(data_.get(RowNum).getZ()); cell4.setCellValue(data_.get(RowNum).getGroup()); } //To change body of generated methods, choose Tools | Templates. }
From source file:com.github.dougkelly88.FLIMPlateReaderGUI.SequencingClasses.Classes.TimeCourseTableModel.java
public void saveTimeCourseTableModelAsSpreadsheet() { // Save FilterTable in third sheet of wb .xls // Initialize third sheet HSSFSheet sheet3 = HCAFLIMPluginFrame.wb.createSheet("TimeCourseSequencing"); // Initialize first row with headers int RowSize = data_.size(); HSSFRow row0 = sheet3.createRow(0);//from www.j av a 2 s . co m HSSFCell cell00 = row0.createCell(0); HSSFCell cell01 = row0.createCell(1); HSSFCell cell02 = row0.createCell(2); cell00.setCellValue("Time (s)"); cell01.setCellValue("Liquid dispense?"); cell02.setCellValue("Liquid dispension well(s)"); // write row for row from table to sheet for (int RowNum = 0; RowNum < RowSize; RowNum++) { HSSFRow row = sheet3.createRow(RowNum + 1); HSSFCell cell0 = row.createCell(0); HSSFCell cell1 = row.createCell(1); HSSFCell cell2 = row.createCell(2); cell0.setCellValue(data_.get(RowNum).getTimeCell()); cell1.setCellValue(data_.get(RowNum).getLDState()); cell2.setCellValue((RichTextString) data_.get(RowNum).getLdWells()); } //To change body of generated methods, choose Tools | Templates. }