Example usage for org.apache.poi.xssf.usermodel XSSFSheet toString

List of usage examples for org.apache.poi.xssf.usermodel XSSFSheet toString

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFSheet toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:FormatConvert.exceloperation.Excel2csv.java

public static void SeperatorExcel2sheet(String excelfile, String targetdir) {
    try {//from   w w  w  .j a  v a  2  s. co m
        FileInputStream is = (new FileInputStream(excelfile));
        if (excelfile.endsWith(".xlsx")) {
            XSSFWorkbook wb = new XSSFWorkbook(is);
            int sheetnub = wb.getNumberOfSheets();
            for (int i = 0; i < sheetnub; i++) {
                XSSFSheet sheet = wb.getSheetAt(i);
                if (sheet.toString() != null) {
                    String temfile = targetdir + "\\" + sheet.getSheetName() + ".csv";
                    Excel2csv.copySheets2CSV(sheet, temfile);
                }
            }
        } else {
            HSSFWorkbook wb = new HSSFWorkbook(is);
            int sheetnub = wb.getNumberOfSheets();
            for (int i = 0; i < sheetnub; i++) {
                HSSFSheet sheet = wb.getSheetAt(i);
                if (sheet.toString() != null) {
                    String temfile = targetdir + "\\" + sheet.getSheetName() + ".csv";
                    Excel2csv.copySheets2CSV(sheet, temfile);
                }
            }
        }

    } catch (Exception ioe) {
        ioe.printStackTrace();
    }
}

From source file:FormatConvert.exceloperation.ExcelOperation.java

public static void SeperatorExcel2sheet(String excelfile, String targetdir) {
    try {//from w ww.ja  v  a  2 s  .  c  o m
        FileInputStream is = (new FileInputStream(excelfile));
        if (excelfile.endsWith(".xlsx")) {
            XSSFWorkbook wb = new XSSFWorkbook(is);
            int sheetnub = wb.getNumberOfSheets();
            for (int i = 0; i < sheetnub; i++) {
                XSSFSheet sheet = wb.getSheetAt(i);
                if (sheet.toString() != null) {
                    Workbook wb2 = new XSSFWorkbook();
                    XSSFSheet tempsheet = (XSSFSheet) wb2.createSheet();
                    Util.copySheets(tempsheet, sheet, true);
                    //tempsheet=wb.cloneSheet(i);
                    //tempsheet = sheet;
                    String temfile = targetdir + "\\" + sheet.getSheetName() + ".xlsx";
                    FileOutputStream fileOut = new FileOutputStream(temfile);
                    wb2.write(fileOut);
                    fileOut.close();
                }
            }
        } else {
            HSSFWorkbook wb = new HSSFWorkbook(is);
            int sheetnub = wb.getNumberOfSheets();
            for (int i = 0; i < sheetnub; i++) {
                HSSFSheet sheet = wb.getSheetAt(i);
                if (sheet.toString() != null) {
                    Workbook wb2 = new HSSFWorkbook();
                    HSSFSheet tempsheet = (HSSFSheet) wb2.createSheet();
                    Util.copySheets(tempsheet, sheet, true);
                    //tempsheet=wb.cloneSheet(i);
                    //tempsheet = sheet;
                    String temfile = targetdir + "\\" + sheet.getSheetName() + ".xlsx";
                    FileOutputStream fileOut = new FileOutputStream(temfile);
                    wb2.write(fileOut);
                    fileOut.close();
                }
            }
        }

    } catch (Exception ioe) {
        ioe.printStackTrace();
    }
}