标签:poi
HSSFWorkbook workbook = new HSSFWorkbook()。
保存操作用「HSSFWorkbook」类的「write」方法:参数是作为保存对象的输出流对象「OutputStream」。package linkin; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.hssf.usermodel.HSSFWorkbook; public class Linkin { public static void main(String[] args) { HSSFWorkbook workbook = new HSSFWorkbook();//创建一个空白的workbook FileOutputStream out = null; try { out = new FileOutputStream("sample.xls"); //fileOut= new FileOutputStream("c:\\workbook.xls"); //fileOut= new FileOutputStream("c:/workbook.xls"); workbook.write(out);//调用HSSFWorkbook类的write方法写入到输出流 System.out.println("OK"); } catch (IOException e) { System.out.println(e.toString()); } finally { try { out.close(); } catch (IOException e) { System.out.println(e.toString()); } } } }
package linkin; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; public class Linkin { public static void main(String[] args) { FileInputStream in = null; HSSFWorkbook workbook = null; try { in = new FileInputStream("sample1.xls");//将excel文件转为输入流 POIFSFileSystem fs = new POIFSFileSystem(in);//构建POIFSFileSystem类对象,用输入流构建 workbook = new HSSFWorkbook(fs);//创建个workbook,根据POIFSFileSystem对象 System.out.println("OK"); } catch (IOException e) { System.out.println(e.toString()); } finally { try { in.close(); } catch (IOException e) { System.out.println(e.toString()); } } FileOutputStream out = null; try { out = new FileOutputStream("sample2.xls"); workbook.write(out); System.out.println("OK"); } catch (IOException e) { System.out.println(e.toString()); } finally { try { out.close(); } catch (IOException e) { System.out.println(e.toString()); } } } }
标签:poi
原文地址:http://blog.csdn.net/u011794238/article/details/46275267