POI apache下一行如果不是空的话

时间:2016-08-23 22:20:10

标签: java android apache apache-poi

我在一个带有POI的excel文件中写道,我想如果该行已经完成,它会在不擦除我的xls文件中已有的内容后传递行!

我找不到有效的方法。

目前我的代码是:

 private static boolean saveExcelFile(Context context, String fileName) {


    // check if available and not read only
    if (!isExternalStorageAvailable() || isExternalStorageReadOnly()) {
        Log.w("FileUtils", "Storage not available or read only");
        return false;
    }

    boolean success = false;

    //New Workbook
    Workbook wb = new HSSFWorkbook();

    Cell c = null;

    //Cell style for header row
    CellStyle cs = wb.createCellStyle();
    cs.setFillForegroundColor(HSSFColor.LIME.index);
    cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

    //New Sheet
    Sheet sheet1 = null;
    sheet1 = wb.createSheet("myOrder");

    // Generate column headings

    Row row = sheet1.createRow(0);

    c = row.createCell(0);
    c.setCellValue("Item Number");
    c.setCellStyle(cs);

    c = row.createCell(1);
    c.setCellValue("Quantity");
    c.setCellStyle(cs);

    c = row.createCell(2);
    c.setCellValue("Price");
    c.setCellStyle(cs);

    sheet1.setColumnWidth(0, (15 * 500));
    sheet1.setColumnWidth(1, (15 * 500));
    sheet1.setColumnWidth(2, (15 * 500));

    // Create a path where we will place our List of objects on external storage
    File file = new File(context.getExternalFilesDir(null), fileName);
    FileOutputStream os = null;

    try {
        os = new FileOutputStream(file);
        wb.write(os);
        Log.w("FileUtils", "Writing file" + file);
        success = true;
    } catch (IOException e) {
        Log.w("FileUtils", "Error writing " + file, e);
    } catch (Exception e) {
        Log.w("FileUtils", "Failed to save file", e);
    } finally {
        try {
            if (null != os)
                os.close();
        } catch (Exception ex) {
        }
    }

    return success;
}

你有什么想法吗?

0 个答案:

没有答案