Search in sources :

Example 1 with CellView

use of jxl.CellView in project network-monitor by caarmen.

the class ExcelExport method resizeColumn.

/**
 * Calculates the optimal width of the column and sets the column width to that value. The width will be large enough to fit the contents of all the cells
 * after the header, and large enough to fit the largest word in the header.
 */
private void resizeColumn(int col) {
    String columnName = mSheet.getCell(col, 0).getContents();
    Log.v(TAG, "resizeColumn " + col + ": " + columnName);
    // Make sure the column width is large enough to fit this column name (plus a space for extra padding).
    int columnWidth = getLongestWordLength(columnName);
    // disable the autosize, so I have to calculate this myself...)
    for (int i = 1; i <= mRowCount; i++) {
        String cellValue = mSheet.getCell(col, i).getContents();
        int cellWidth = cellValue.length();
        if (cellWidth > columnWidth)
            columnWidth = cellWidth;
    }
    Log.v(TAG, "columnWidth: " + columnWidth);
    // The width of the column is the number of characters multiplied by 256.
    // From the Excel documentation, the width of a column is an:
    // "integer that specifies the column width in units of 1/256th of a character width.
    // Character width is defined as the maximum digit width of the numbers 0, 1, 2, ... 9
    // as rendered in the Normal style's font."
    // Some of our letters may be wider than the digits 0-9. So we may need to overestimate
    // the width we need by a bit. Adding a padding of 4 characters seems to be ok
    // for this app.
    CellView columnView = mSheet.getColumnView(col);
    columnView.setSize((columnWidth + 4) * 256);
    mSheet.setColumnView(col, columnView);
}
Also used : CellView(jxl.CellView)

Example 2 with CellView

use of jxl.CellView in project aws-doc-sdk-examples by awsdocs.

the class WriteExcel method createLabel.

// Create Headings in the Excel spreadsheet.
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, "Photo");
    addCaption(sheet, 1, 0, "Label");
    addCaption(sheet, 2, 0, "Confidence");
}
Also used : WritableFont(jxl.write.WritableFont) WritableCellFormat(jxl.write.WritableCellFormat) CellView(jxl.CellView)

Example 3 with CellView

use of jxl.CellView in project aws-doc-sdk-examples by awsdocs.

the class WriteExcel method createLabel.

// Create Headings in the Excel spreadsheet
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, "Age Range");
    addCaption(sheet, 1, 0, "Beard");
    addCaption(sheet, 2, 0, "Eye glasses");
    addCaption(sheet, 3, 0, "Eyes open");
    addCaption(sheet, 4, 0, "Mustache");
    addCaption(sheet, 4, 0, "Smile");
}
Also used : WritableFont(jxl.write.WritableFont) WritableCellFormat(jxl.write.WritableCellFormat) CellView(jxl.CellView)

Example 4 with CellView

use of jxl.CellView in project aws-doc-sdk-examples by awsdocs.

the class WriteExcel method createLabel.

// Create Headings in the Excel spreadsheet
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 a bold font with underlining
    WritableFont times10ptBoldUnderline = new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD, false, UnderlineStyle.SINGLE);
    timesBoldUnderline = new WritableCellFormat(times10ptBoldUnderline);
    // 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");
}
Also used : WritableFont(jxl.write.WritableFont) WritableCellFormat(jxl.write.WritableCellFormat) CellView(jxl.CellView)

Example 5 with CellView

use of jxl.CellView in project aws-doc-sdk-examples by awsdocs.

the class WriteExcel method createLabel.

// Create Headings in the Excel spreadsheet
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");
}
Also used : WritableFont(jxl.write.WritableFont) WritableCellFormat(jxl.write.WritableCellFormat) CellView(jxl.CellView)

Aggregations

CellView (jxl.CellView)8 WritableCellFormat (jxl.write.WritableCellFormat)5 WritableFont (jxl.write.WritableFont)5 JXLException (jxl.JXLException)1