jxl.write.WritableSheet Java Examples

The following examples show how to use jxl.write.WritableSheet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResultExport.java    From yeti with MIT License 8 votes vote down vote up
public static void ExportCertToXLS(String filename, ArrayList<Object> data) throws IOException {
    try {
        WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, true);
        WritableCellFormat titleformat = new WritableCellFormat(titleFont);
        WritableWorkbook workbook = Workbook.createWorkbook(new File(filename));
        WritableSheet sheet = workbook.createSheet("SSLCert CN", 0);
        sheet.addCell(new Label(0, 0, "IP address", titleformat));
        sheet.addCell(new Label(1, 0, "Host name", titleformat));
        sheet.addCell(new Label(2, 0, "Domain name", titleformat));
        int nextRow = 1;
        Iterator i = data.iterator();
        while (i.hasNext()) {
            CertResult res = (CertResult) i.next();
            sheet.addCell(new Label(0, nextRow, res.getIpAddress()));
            sheet.addCell(new Label(1, nextRow, res.getHostName()));
            sheet.addCell(new Label(2, nextRow, res.getDomainName()));
            nextRow++;
        }
        workbook.write();
        workbook.close();
    } catch (WriteException ex) {
        Logger.getLogger("resultExport.ExportForwardLookupsToXLS").log(Level.SEVERE, null, ex);
    }
}
 
Example #2
Source File: ResultExport.java    From yeti with MIT License 8 votes vote down vote up
public static void ExportTLDToXLS(String filename, ArrayList<Object> data) throws IOException {
    try {
        WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, true);
        WritableCellFormat titleformat = new WritableCellFormat(titleFont);
        WritableWorkbook workbook = Workbook.createWorkbook(new File(filename));
        WritableSheet sheet = workbook.createSheet("TLD Expand", 0);
        sheet.addCell(new Label(0, 0, "Domain name", titleformat));
        sheet.addCell(new Label(1, 0, "Name server", titleformat));
        sheet.addCell(new Label(2, 0, "Admin name", titleformat));
        sheet.addCell(new Label(3, 0, "Registrant", titleformat));
        int nextRow = 1;
        Iterator i = data.iterator();
        while (i.hasNext()) {
            DomainResult res = (DomainResult) i.next();
            sheet.addCell(new Label(0, nextRow, res.getDomainName()));
            sheet.addCell(new Label(1, nextRow, res.getNameServer()));
            sheet.addCell(new Label(2, nextRow, res.getAdminName()));
            sheet.addCell(new Label(3, nextRow, res.getRegistrant()));
            nextRow++;
        }
        workbook.write();
        workbook.close();
    } catch (WriteException ex) {
        Logger.getLogger("resultExport.ExportForwardLookupsToXLS").log(Level.SEVERE, null, ex);
    }
}
 
Example #3
Source File: ResultExport.java    From yeti with MIT License 8 votes vote down vote up
public static void ExportForwardLookupsToXLS(String filename, List<Object> data) throws IOException {
    try {
        WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, true);
        WritableCellFormat titleformat = new WritableCellFormat(titleFont);
        WritableWorkbook workbook = Workbook.createWorkbook(new File(filename));
        WritableSheet sheet = workbook.createSheet("Forward lookups", 0);
        sheet.addCell(new Label(0, 0, "Domain name", titleformat));
        sheet.addCell(new Label(1, 0, "Host name", titleformat));
        sheet.addCell(new Label(2, 0, "IP address", titleformat));
        sheet.addCell(new Label(3, 0, "Type", titleformat));
        int nextRow = 1;
        Iterator i = data.iterator();
        while (i.hasNext()) {
            ForwardLookupResult res = (ForwardLookupResult) i.next();
            sheet.addCell(new Label(0, nextRow, res.getDomainName()));
            sheet.addCell(new Label(1, nextRow, res.getHostName()));
            sheet.addCell(new Label(2, nextRow, res.getIpAddress()));
            sheet.addCell(new Label(3, nextRow, res.getLookupType()));
            nextRow++;
        }
        workbook.write();
        workbook.close();
    } catch (WriteException ex) {
        Logger.getLogger("resultExport.ExportForwardLookupsToXLS").log(Level.SEVERE, null, ex);
    }
}
 
Example #4
Source File: DownloadFileService.java    From pacbot with Apache License 2.0 8 votes vote down vote up
/**
 * Adds the cell.
 *
 * @param writablesheet the writablesheet
 * @param issueDetail the issue detail
 * @param cellFormat the cell format
 * @param columnIndex the column index
 * @param columns the columns
 * @throws WriteException the write exception
 */
private void addCell(WritableSheet writablesheet, JsonObject issueDetail, WritableCellFormat cellFormat,
        int columnIndex,List<String>columns) throws WriteException {
    int rowIndex = 0;

    for (String clm : columns) {
        if (issueDetail.has(clm)) {
            if (issueDetail.get(clm).isJsonNull()) {
                writablesheet.addCell(new Label(rowIndex++, 1 + columnIndex, "No Data", cellFormat));
            } else {
                writablesheet.addCell(new Label(rowIndex++, 1 + columnIndex, issueDetail.get(clm).getAsString(),
                        cellFormat));
            }

        }
    }
}
 
Example #5
Source File: DownloadFileService.java    From pacbot with Apache License 2.0 8 votes vote down vote up
/**
 * Format writable sheet.
 *
 * @param writablesheet the writable sheet
 * @param columns the columns
 * @throws WriteException the write exception
 */
private void formatWritableSheet(WritableSheet writablesheet,List<String>columns) throws WriteException {
    WritableFont cellFonts = new WritableFont(WritableFont.createFont("Calibri"), ELEVEN, WritableFont.BOLD, false,
            UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK);
    WritableCellFormat cellFormats = new WritableCellFormat(cellFonts);
    cellFormats.setBorder(Border.ALL, BorderLineStyle.THIN);
    cellFormats.setBackground(Colour.WHITE);
    int labelIndex = 0;
    for (String clm : columns) {
        writablesheet.addCell(new Label(labelIndex, 0, clm.replaceAll("_", ""), cellFormats));
        CellView cell = writablesheet.getColumnView(labelIndex);
        cell.setAutosize(true);
        writablesheet.setColumnView(labelIndex, cell);
        labelIndex++;
    }
}
 
Example #6
Source File: ResultExport.java    From yeti with MIT License 7 votes vote down vote up
public static void ExportReverseToXLS(String filename, ArrayList<Object> data) throws IOException {
    try {
        WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, true);
        WritableCellFormat titleformat = new WritableCellFormat(titleFont);
        WritableWorkbook workbook = Workbook.createWorkbook(new File(filename));
        WritableSheet sheet = workbook.createSheet("Bing IP search", 0);
        sheet.addCell(new Label(0, 0, "IP address", titleformat));
        sheet.addCell(new Label(1, 0, "Domain name", titleformat));
        sheet.addCell(new Label(2, 0, "Host name", titleformat));
        int nextRow = 1;
        Iterator i = data.iterator();
        while (i.hasNext()) {
            ReverseLookupResult res = (ReverseLookupResult) i.next();
            sheet.addCell(new Label(0, nextRow, res.getIpAddress()));
            sheet.addCell(new Label(1, nextRow, res.getDomainName()));
            sheet.addCell(new Label(2, nextRow, res.getHostName()));
            nextRow++;
        }
        workbook.write();
        workbook.close();
    } catch (WriteException ex) {
        Logger.getLogger("resultExport.ExportReverseToXLS").log(Level.SEVERE, null, ex);
    }
}
 
Example #7
Source File: ExcelUtil.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
     * @MethodName  : setColumnAutoSize
     * @Description : 设置工作表自动列宽和首行加粗
     * @param ws

*/

    private static void setColumnAutoSize(WritableSheet ws,int extraWith){
        //获取本列的最宽单元格的宽度
        for(int i=0;i<ws.getColumns();i++){
            int colWith=0;
            for(int j=0;j<ws.getRows();j++){
                String content=ws.getCell(i,j).getContents().toString();
                int cellWith=content.length();
                if(colWith<cellWith){
                    colWith=cellWith;
                }
            }
            //设置单元格的宽度为最宽宽度+额外宽度
            ws.setColumnView(i, colWith+extraWith);
        }

    }
 
Example #8
Source File: WriteExcel.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public java.io.InputStream write( List<WorkItem> list) throws IOException, WriteException {
    java.io.OutputStream os = new java.io.ByteArrayOutputStream() ;
    WorkbookSettings wbSettings = new WorkbookSettings();

    wbSettings.setLocale(new Locale("en", "EN"));

    // Create a Workbook - pass the OutputStream
    WritableWorkbook workbook = Workbook.createWorkbook(os, wbSettings);
    workbook.createSheet("Work Item Report", 0);
    WritableSheet excelSheet = workbook.getSheet(0);
    createLabel(excelSheet) ;
    int size = createContent(excelSheet, list);

    // Close the workbook
    workbook.write();
    workbook.close();

    // Get an inputStram that represents the Report
    java.io.ByteArrayOutputStream stream = new java.io.ByteArrayOutputStream();
    stream = (java.io.ByteArrayOutputStream)os;
    byte[] myBytes = stream.toByteArray();
    java.io.InputStream is = new java.io.ByteArrayInputStream(myBytes) ;

    return is ;
}
 
Example #9
Source File: SpreadSheetWriter.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void writeFieldRow(WritableSheet spreadSheet, HashMap<String, Object> fieldRow, int maxIndexedColumnIndex, int r, ExcelCellFormat f,
		HashMap<String, WritableCellFormat> cellFormats) throws Exception {
	if (fieldRow != null && distinctColumnNames != null && distinctColumnNames.size() > 0) {
		int c = maxIndexedColumnIndex;
		for (int d = 0; d < distinctColumnNames.size(); d++) {
			String columnName = distinctColumnNames.get(d);
			Object fieldValue = fieldRow.get(columnName);
			Integer columnIndex = getColumnIndex(columnName);
			if (columnIndex == null) {
				c++;
				columnIndex = c;
			}
			if (fieldValue != null) {
				ExcelUtil.writeCell(spreadSheet, columnIndex.intValue(), r, fieldValue.getClass(), fieldValue, f, cellFormats);
			} else {
				ExcelUtil.writeCell(spreadSheet, columnIndex.intValue(), r, String.class, null, f, cellFormats);
			}
		}
	}
}
 
Example #10
Source File: AuditTrailExcelWriter.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void applySpreadsheetSettings(WritableSheet spreadSheet, int sheetIndex) throws Exception {
	Integer scaleFactor;
	switch (sheetIndex) {
		case 0:
			scaleFactor = Settings.getIntNullable(AuditTrailExcelSettingCodes.AUDIT_TRAIL_SCALE_FACTOR, Bundle.AUDIT_TRAIL_EXCEL,
					AuditTrailExcelDefaultSettings.AUDIT_TRAIL_SCALE_FACTOR);
			if (Settings.getBoolean(AuditTrailExcelSettingCodes.AUDIT_TRAIL_APPEND_HEADER_FOOTER, Bundle.AUDIT_TRAIL_EXCEL,
					AuditTrailExcelDefaultSettings.AUDIT_TRAIL_APPEND_HEADER_FOOTER)) {
				appendHeaderFooter(spreadSheet.getSettings().getHeader(), spreadSheet.getSettings().getFooter());
			}
			break;
		default:
			scaleFactor = Settings.getIntNullable(AuditTrailExcelSettingCodes.ECRF_FIELD_STATUS_SCALE_FACTOR, Bundle.AUDIT_TRAIL_EXCEL,
					AuditTrailExcelDefaultSettings.ECRF_FIELD_STATUS_SCALE_FACTOR);
			if (Settings.getBoolean(AuditTrailExcelSettingCodes.ECRF_FIELD_STATUS_APPEND_HEADER_FOOTER, Bundle.AUDIT_TRAIL_EXCEL,
					AuditTrailExcelDefaultSettings.ECRF_FIELD_STATUS_APPEND_HEADER_FOOTER)) {
				appendHeaderFooter(spreadSheet.getSettings().getHeader(), spreadSheet.getSettings().getFooter());
			}
			break;
	}
	if (scaleFactor != null && scaleFactor.intValue() > 0) {
		spreadSheet.getSettings().setScaleFactor(scaleFactor);
	}
}
 
Example #11
Source File: ExcelUtil.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
     * @MethodName  : setColumnAutoSize
     * @Description : 设置工作表自动列宽和首行加粗
     * @param ws

*/

    private static void setColumnAutoSize(WritableSheet ws,int extraWith){
        //获取本列的最宽单元格的宽度
        for(int i=0;i<ws.getColumns();i++){
            int colWith=0;
            for(int j=0;j<ws.getRows();j++){
                String content=ws.getCell(i,j).getContents().toString();
                int cellWith=content.length();
                if(colWith<cellWith){
                    colWith=cellWith;
                }
            }
            //设置单元格的宽度为最宽宽度+额外宽度
            ws.setColumnView(i, colWith+extraWith);
        }

    }
 
Example #12
Source File: DownloadFileService.java    From pacbot with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the file bytes.
 *
 * @param issueDetails the issue details
 * @param methodType the method type
 * @param columns the columns
 * @return the file bytes
 * @throws WriteException the write exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
private byte[] getFileBytes(JsonArray issueDetails, String methodType, List<String>columns) throws WriteException, IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    WritableWorkbook workbook = Workbook.createWorkbook(baos);
    WritableSheet writablesheet = workbook.createSheet(methodType, 0);
    formatWritableSheet(writablesheet,columns);
    addWritableSheetCells(writablesheet, issueDetails,columns);
    workbook.write();
    workbook.close();
    return baos.toByteArray();
}
 
Example #13
Source File: InventoryBookingsExcelWriter.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void applySpreadsheetSettings(WritableSheet spreadSheet, int sheetIndex) throws Exception {
	Integer scaleFactor = Settings.getIntNullable(InventoryBookingsExcelSettingCodes.SCALE_FACTOR, Bundle.INVENTORY_BOOKINGS_EXCEL,
			InventoryBookingsExcelDefaultSettings.SCALE_FACTOR);
	if (Settings.getBoolean(InventoryBookingsExcelSettingCodes.APPEND_HEADER_FOOTER, Bundle.INVENTORY_BOOKINGS_EXCEL,
			InventoryBookingsExcelDefaultSettings.APPEND_HEADER_FOOTER)) {
		appendHeaderFooter(spreadSheet.getSettings().getHeader(), spreadSheet.getSettings().getFooter());
	}
	if (scaleFactor != null && scaleFactor.intValue() > 0) {
		spreadSheet.getSettings().setScaleFactor(scaleFactor);
	}
}
 
Example #14
Source File: ExcelUtils.java    From jshERP with GNU General Public License v3.0 5 votes vote down vote up
public static String createTempFile(String[] names, String title, List<String[]> objects) throws Exception {
	File excelFile = File.createTempFile(System.currentTimeMillis() + "", ".xls");
	WritableWorkbook wtwb = Workbook.createWorkbook(excelFile);
	WritableSheet sheet = wtwb.createSheet(title, 0);
	sheet.getSettings().setDefaultColumnWidth(20);
	WritableFont wfont = new WritableFont(WritableFont.createFont("楷书"), 15);
	WritableCellFormat format = new WritableCellFormat(wfont);
	WritableFont wfc = new WritableFont(WritableFont.ARIAL, 20,
			WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
			jxl.format.Colour.BLACK);
	WritableCellFormat wcfFC = new WritableCellFormat(wfc);
	wcfFC.setAlignment(Alignment.CENTRE);
	wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);
	// CellView cellView = new CellView();
	// cellView.setAutosize(true); //设置自动大小
	format.setAlignment(Alignment.LEFT);
	format.setVerticalAlignment(VerticalAlignment.TOP);
	sheet.mergeCells(0, 0, names.length - 1, 0);
	sheet.addCell(new Label(0, 0, title, wcfFC));
	int rowNum = 2;
	for (int i = 0; i < names.length; i++) {
		sheet.addCell(new Label(i, 1, names[i], format));
	}
	for (int j = 0; j < objects.size(); j++) {
		String[] obj = objects.get(j);
		for (int h = 0; h < obj.length; h++) {
			sheet.addCell(new Label(h, rowNum, obj[h], format));
		}
		rowNum = rowNum + 1;
	}
	wtwb.write();
	wtwb.close();
	return excelFile.getName();
}
 
Example #15
Source File: ExcelUtils.java    From jshERP with GNU General Public License v3.0 5 votes vote down vote up
public static File exportObjects(String fileName, String[] names,
		String title, List<String[]> objects) throws Exception {
	File excelFile = new File("fileName.xls");
	WritableWorkbook wtwb = Workbook.createWorkbook(excelFile);
	WritableSheet sheet = wtwb.createSheet(title, 0);
	sheet.getSettings().setDefaultColumnWidth(20);
	WritableFont wfont = new WritableFont(WritableFont.createFont("楷书"), 15);
	WritableCellFormat format = new WritableCellFormat(wfont);
	WritableFont wfc = new WritableFont(WritableFont.ARIAL, 20,
			WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
			jxl.format.Colour.BLACK);
	WritableCellFormat wcfFC = new WritableCellFormat(wfc);
	wcfFC.setAlignment(Alignment.CENTRE);
	wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);
	// CellView cellView = new CellView();
	// cellView.setAutosize(true); //设置自动大小
	format.setAlignment(Alignment.LEFT);
	format.setVerticalAlignment(VerticalAlignment.TOP);
	sheet.mergeCells(0, 0, names.length - 1, 0);
	sheet.addCell(new Label(0, 0, title, wcfFC));
	int rowNum = 2;
	for (int i = 0; i < names.length; i++) {
		sheet.addCell(new Label(i, 1, names[i], format));
	}
	for (int j = 0; j < objects.size(); j++) {
		String[] obj = objects.get(j);
		for (int h = 0; h < obj.length; h++) {
			sheet.addCell(new Label(h, rowNum, obj[h], format));
		}
		rowNum = rowNum + 1;

	}
	wtwb.write();
	wtwb.close();
	return excelFile;
}
 
Example #16
Source File: CreateFilePane.java    From pattypan with MIT License 5 votes vote down vote up
/**
 *
 * @param workbook
 * @throws WriteException
 */
private void createTemplateSheet(WritableWorkbook workbook) throws WriteException {
  WritableSheet templateSheet = workbook.createSheet("Template", 1);
  templateSheet.addCell(new Label(0, 0, "'" + Session.WIKICODE));
  //                                    ^^
  // leading apostrophe prevents turning wikitext into formula in Excel

  autoSizeColumn(0, templateSheet);
}
 
Example #17
Source File: HRExcelJExcelBuilder.java    From Spring-MVC-Blueprints with MIT License 5 votes vote down vote up
@Override
protected void buildExcelDocument(Map<String, Object> model,
		WritableWorkbook workbook, HttpServletRequest request,
		HttpServletResponse response) throws Exception {
	
	// get data model which is passed by the Spring container
	List<HrmsLogin> users = (List<HrmsLogin>) model.get("allUsers");
	
	// create a new Excel sheet
	WritableSheet sheet = workbook.createSheet("Master List of Users", 0);
	
	// create header row
	sheet.addCell(new Label(0, 0, "Employee ID"));
	sheet.addCell(new Label(1, 0, "Username"));
	sheet.addCell(new Label(2, 0, "Password"));
	sheet.addCell(new Label(3, 0, "Role"));
	
	
	// create data rows
	int rowCount = 1;
	
	for (HrmsLogin user : users) {
		sheet.addCell(new Label(0, rowCount, user.getHrmsEmployeeDetails().getEmpId()+""));
		sheet.addCell(new Label(1, rowCount, user.getUsername()));
		sheet.addCell(new Label(2, rowCount, user.getPassword()));
		sheet.addCell(new Label(3, rowCount, user.getRole()));
		
		rowCount++;
	}
}
 
Example #18
Source File: DownloadFileService.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the writable sheet cells.
 *
 * @param writablesheet the writablesheet
 * @param issueDetails the issue details
 * @param columns the columns
 * @throws WriteException the write exception
 */
private void addWritableSheetCells(WritableSheet writablesheet, JsonArray issueDetails,List<String>columns) throws WriteException {
    WritableFont cellFont = new WritableFont(WritableFont.createFont("Calibri"), TWELVE);
    cellFont.setColour(Colour.BLACK);
    WritableCellFormat cellFormat = new WritableCellFormat(cellFont);
    cellFormat.setBackground(Colour.WHITE);
    cellFormat.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.GRAY_25);
    for (int columnIndex = 0; columnIndex < issueDetails.size(); columnIndex++) {
        JsonObject issueDetail = issueDetails.get(columnIndex).getAsJsonObject();
        addCell(writablesheet, issueDetail, cellFormat, columnIndex,columns);
    }
}
 
Example #19
Source File: WriteExcel.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
private void createLabel(WritableSheet sheet)
        throws WriteException {
    // Create a times font
    WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10);
    // Define the cell format
    times = new WritableCellFormat(times10pt);
    // Lets automatically wrap the cells
    times.setWrap(true);

    // create create a bold font with unterlines
    WritableFont times10ptBoldUnderline = new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD, false,
            UnderlineStyle.SINGLE);
    timesBoldUnderline = new WritableCellFormat(times10ptBoldUnderline);
    // Lets automatically wrap the cells
    timesBoldUnderline.setWrap(true);

    CellView cv = new CellView();
    cv.setFormat(times);
    cv.setFormat(timesBoldUnderline);
    cv.setAutosize(true);

    // Write a few headers
    addCaption(sheet, 0, 0, "Writer");
    addCaption(sheet, 1, 0, "Date");
    addCaption(sheet, 2, 0, "Guide");
    addCaption(sheet, 3, 0, "Description");
    addCaption(sheet, 4, 0, "Status");
}
 
Example #20
Source File: TableOutputter.java    From morf with Apache License 2.0 5 votes vote down vote up
/**
 * Outputs the example data rows.
 *
 * @param numberOfExamples to output
 * @param workSheet to add the data rows to
 * @param table to get metadata from
 * @param startRow to start adding the example rows at
 * @param records to add as examples
 * @return the new row to carry on outputting at
 * @throws WriteException if any of the writes to workSheet fail
 */
private int outputExampleData(final Integer numberOfExamples, WritableSheet workSheet, Table table, final int startRow, Iterable<Record> records) throws WriteException {
  int currentRow = startRow;

  int rowsOutput = 0;
  for (Record record : records) {

    if (currentRow >= MAX_EXCEL_ROWS) {
      continue;
    }

    if (numberOfExamples != null && rowsOutput >= numberOfExamples) {
      // Need to continue the loop rather than break as we need to close
      // the connection which happens at the end of iteration...
      continue;
    }

    record(currentRow, workSheet, table, record);
    rowsOutput++;
    currentRow++;
  }

  if (currentRow >= MAX_EXCEL_ROWS) {
    // This is a fix for WEB-56074. It will be removed if/when WEB-42351 is developed.
    throw new RowLimitExceededException("Output for table '" + table.getName() + "' exceeds the maximum number of rows (" + MAX_EXCEL_ROWS + ") in an Excel worksheet. It will be truncated.");
  }

  currentRow++;
  return currentRow;
}
 
Example #21
Source File: SpreadsheetDataSetConsumer.java    From morf with Apache License 2.0 5 votes vote down vote up
/**
 * Create the index worksheet.
 *
 * <p>This also creates links back to the index in each of the worksheets.</p>
 */
public void createIndex() {
  WritableSheet sheet = workbook.createSheet(spreadsheetifyName("Index"), 0);
  createTitle(sheet, "Index");

  try {
    // Create links for each worksheet, apart from the first sheet which is the
    // index we're currently creating
    final String[] names = workbook.getSheetNames();
    for (int currentSheet = 1; currentSheet < names.length; currentSheet++) {
      // Create the link from the index to the table's worksheet
      WritableHyperlink link = new WritableHyperlink(0, currentSheet - 1 + NUMBER_OF_ROWS_IN_TITLE, names[currentSheet], workbook.getSheet(currentSheet), 0, 0);
      sheet.addHyperlink(link);

      //Add the filename in column B (stored in cell B2 of each sheet)
      String fileName = workbook.getSheet(currentSheet).getCell(1, 1).getContents();
      Label fileNameLabel = new Label(1, currentSheet - 1 + NUMBER_OF_ROWS_IN_TITLE, fileName);
      WritableFont fileNameFont = new WritableFont(WritableFont.ARIAL,10,WritableFont.NO_BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.BLACK);
      WritableCellFormat fileNameFormat = new WritableCellFormat(fileNameFont);
      fileNameLabel.setCellFormat(fileNameFormat);
      sheet.addCell(fileNameLabel);

      // Create the link back to the index
      link = new WritableHyperlink(0, 1, "Back to index", sheet, 0, currentSheet + NUMBER_OF_ROWS_IN_TITLE - 1);
      workbook.getSheet(currentSheet).addHyperlink(link);
      //Set column A of each sheet to be wide enough to show "Back to index"
      workbook.getSheet(currentSheet).setColumnView(0, 13);
    }

    // Make Column A fairly wide to show tab names and hide column B
    sheet.setColumnView(0, 35);
    sheet.setColumnView(1, 0);

  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example #22
Source File: WriteExcel.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
private int createContent(WritableSheet sheet, List<WorkItem> list) throws WriteException {

        int size = list.size() ;

        // Add customer data to the Excel report
        for (int i = 0; i < size; i++) {

            WorkItem wi = list.get(i);

            //Get tne work item values
            String name = wi.getName();
            String guide = wi.getGuide();
            String date = wi.getDate();
            String des = wi.getDescription();
            String status = wi.getStatus();

            // First column
            addLabel(sheet, 0, i+2, name);
            // Second column
            addLabel(sheet, 1, i+2, date);

            // Third column
            addLabel(sheet, 2, i+2,guide);

            // Forth column
            addLabel(sheet, 3, i+2, des);

            // Fifth column
            addLabel(sheet, 4, i+2, status);

        }
        return size;
    }
 
Example #23
Source File: XlsExporterContext.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
public XlsExporterContext(XlsExporter exporter, String fileName) {
	this.exporter = exporter;
	this.fileName = fileName;
	this.auth = null;
	this.workbook = null;
	spreadSheetMap = new HashMap<RowWriter, WritableSheet>();
	entityIdMap = new HashMap<RowWriter, Long>();
}
 
Example #24
Source File: ExcelResultsTable.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
private static void setExcelPrintPageFormat ( WritableSheet sheet ) {
    SheetSettings settings = sheet.getSettings();
    settings.setPaperSize( ExcelReportConstants.PAPER_SIZE );
    settings.setOrientation( ExcelReportConstants.PAGE_ORIENTATION );
    settings.setScaleFactor( ExcelReportConstants.SCALE_FACTOR );
    settings.setLeftMargin( ExcelReportConstants.LEFT_MARGIN );
    settings.setRightMargin( ExcelReportConstants.RIGHT_MARGIN );
    settings.setTopMargin( ExcelReportConstants.TOP_MARGIN );
    settings.setBottomMargin( ExcelReportConstants.BOTTOM_MARGIN );
}
 
Example #25
Source File: ExcelUtil.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void writeHead(WritableSheet spreadSheet, int c, int r, String columnName, ExcelCellFormat f, HashMap<String, WritableCellFormat> cellFormats) throws Exception {
	if (spreadSheet != null) {
		WritableCell cell;
		if (f.isOverrideFormat()) {
			cell = new jxl.write.Label(c, r, columnName, getHeadCellFormat(f, cellFormats));
		} else {
			cell = new jxl.write.Label(c, r, columnName);
		}
		addCell(cell, spreadSheet, c, r, f);
	}
}
 
Example #26
Source File: ExcelUtil.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void writeCell(WritableSheet spreadSheet, int c, int r, Class returnType, Object value, ExcelCellFormat f, HashMap<String, WritableCellFormat> cellFormats)
		throws Exception {
	if (spreadSheet != null) {
		WritableCell cell = createCell(returnType, c, r, value, f, cellFormats);
		addCell(cell, spreadSheet, c, r, f);
	}
}
 
Example #27
Source File: ExcelUtil.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static WritableCellFormat getRowCellFormat(WritableSheet spreadSheet, int c, int r) {
	if (spreadSheet != null) {
		Cell cell = spreadSheet.getCell(c, r);
		if (cell != null) {
			CellFormat cellFormat = cell.getCellFormat();
			if (cellFormat != null) {
				return new WritableCellFormat(cellFormat);
			}
		}
	}
	return null;
}
 
Example #28
Source File: TeamMembersExcelWriter.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void applySpreadsheetSettings(WritableSheet spreadSheet, int sheetIndex) throws Exception {
	Integer scaleFactor = Settings.getIntNullable(TeamMembersExcelSettingCodes.SCALE_FACTOR, Bundle.TEAM_MEMBERS_EXCEL, TeamMembersExcelDefaultSettings.SCALE_FACTOR);
	if (Settings.getBoolean(TeamMembersExcelSettingCodes.APPEND_HEADER_FOOTER, Bundle.TEAM_MEMBERS_EXCEL, TeamMembersExcelDefaultSettings.APPEND_HEADER_FOOTER)) {
		appendHeaderFooter(spreadSheet.getSettings().getHeader(), spreadSheet.getSettings().getFooter());
	}
	if (scaleFactor != null && scaleFactor.intValue() > 0) {
		spreadSheet.getSettings().setScaleFactor(scaleFactor);
	}
}
 
Example #29
Source File: ClassifierResultsAnalysis.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
protected static void jxl_buildStatSheets_timings(WritableWorkbook wb, String basePath, PerformanceMetric metric, int statIndex, String evalSet, String timingType) {
    // ************* the difference: timings folder assumed instead of going by the specific metric name
    //i.e Timings/TRAIN/TrainTimings and Timings/TEST/TestTimings    
    //instead of TrainTimings/TRAIN/TrainTimings ... 
    String metricPath = basePath + "Timings"+timingType+"/" + evalSet + "/";

    WritableSheet avgsSheet = wb.createSheet(metric.name, wb.getNumberOfSheets());
    String testCSV = metricPath + fileNameBuild_avgsFile(evalSet, metric);
    jxl_copyCSVIntoSheet(avgsSheet, testCSV);

    WritableSheet summarySheet = wb.createSheet(metric.name+"SigDiffs", wb.getNumberOfSheets());
    String summaryCSV = metricPath + fileNameBuild_summaryFile(evalSet, metric);
    jxl_copyCSVIntoSheet(summarySheet, summaryCSV);

}
 
Example #30
Source File: ClassifierResultsAnalysis.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
protected static void jxl_buildStatSheets(WritableWorkbook wb, String basePath, PerformanceMetric metric, int statIndex) {
    String metricPath = basePath + metric + "/";
    String testMetricPath = metricPath + testLabel + "/";

    WritableSheet testSheet = wb.createSheet(metric+"Test", wb.getNumberOfSheets());
    String testCSV = testMetricPath+ fileNameBuild_avgsFile(testLabel, metric);
    jxl_copyCSVIntoSheet(testSheet, testCSV);

    WritableSheet summarySheet = wb.createSheet(metric+"TestSigDiffs", wb.getNumberOfSheets());
    String summaryCSV = testMetricPath + fileNameBuild_summaryFile(testLabel, metric);
    jxl_copyCSVIntoSheet(summarySheet, summaryCSV);
}