poi读取excel模板,填充内容并导出,支持导出2007支持公式自动计算
来源:互联网 发布:新网域名转到腾讯云 编辑:程序博客网 时间:2024/06/05 07:53
非常感谢这位同学,转自: http://blog.csdn.net/xiongshengwu/article/details/53696649
/** * 版权所有(C) 2016 * @author www.xiongge.club * @date 2016-12-7 上午10:03:29 */package xlsx;/** * @ClassName: CreateExcel * @Description: TODO() * @author www.xiongge.club * @date 2016-12-7 上午10:03:29 * */
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* @author Gerrard
* @Discreption 根据已有的Excel模板,修改模板内容生成新Excel
*/
public class CreateExcel {
/**
*
*(2003 xls后缀 导出)
* @param TODO
* @return void 返回类型
* @author xsw
* @2016-12-7上午10:44:00
*/
public static void createXLS() throws IOException{
//excel模板路径
File fi=new File("D:\\offer_template.xls");
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(fi));
//读取excel模板
HSSFWorkbook wb = new HSSFWorkbook(fs);
//读取了模板内所有sheet内容
HSSFSheet sheet = wb.getSheetAt(0);
//如果这行没有了,整个公式都不会有自动计算的效果的
sheet.setForceFormulaRecalculation(true);
//在相应的单元格进行赋值
HSSFCell cell = sheet.getRow(11).getCell(6);//第11行 第6列
cell.setCellValue(1);
HSSFCell cell2 = sheet.getRow(11).getCell(7);
cell2.setCellValue(2);
sheet.getRow(12).getCell(6).setCellValue(12);
sheet.getRow(12).getCell(7).setCellValue(12);
//修改模板内容导出新模板
FileOutputStream out = new FileOutputStream("D:/export.xls");
wb.write(out);
out.close();
}
/**
*
*(2007 xlsx后缀 导出)
* @param TODO
* @return void 返回类型
* @author xsw
* @2016-12-7上午10:44:30
*/
public static void createXLSX() throws IOException{
//excel模板路径
File fi=new File("D:\\offer_template.xlsx");
InputStream in = new FileInputStream(fi);
//读取excel模板
XSSFWorkbook wb = new XSSFWorkbook(in);
//读取了模板内所有sheet内容
XSSFSheet sheet = wb.getSheetAt(0);
//如果这行没有了,整个公式都不会有自动计算的效果的
sheet.setForceFormulaRecalculation(true);
//在相应的单元格进行赋值
XSSFCell cell = sheet.getRow(11).getCell(6);//第11行 第6列
cell.setCellValue(1);
XSSFCell cell2 = sheet.getRow(11).getCell(7);
cell2.setCellValue(2);
sheet.getRow(12).getCell(6).setCellValue(12);
sheet.getRow(12).getCell(7).setCellValue(12);
//修改模板内容导出新模板
FileOutputStream out = new FileOutputStream("D:/export.xlsx");
wb.write(out);
out.close();
}
public static void main(String[] args) throws IOException {
//excle 2003
createXLS();
//excle 2007
createXLSX();
}
}
模板风格不变,只是填充内容,生成新excel,支持xls 和 xlsx。
The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)
//如果这行没有了,整个公式都不会有自动计算的效果的
sheet.setForceFormulaRecalculation(true);
- poi读取excel模板,填充内容并导出,支持导出2007支持公式自动计算
- poi读取excel模板,填充内容并导出,支持导出2007支持公式自动计算
- poi读取excel模板,填充内容并导出,支持导出2007支持公式自动计算
- 导出excel,并支持分sheet导出
- poi导出excel,支持合并的单元格
- poi excel带公式导出
- poi excel带公式导出
- poi读取excel内容(公式)
- POI根据EXCEL模板,修改内容导出新EXCEL
- 基于apache POI excel导出,支持多列多条件。
- poi根据模板导出excel
- POI Excel导出,模板导出,代码解析
- poi导出excel,支持2007和2003,支持javabean,利用反射对poi进行简单封装,支持任意实体和乱序的excel表格
- 利用poi导出excel,并自动生成表头
- poi/jxls导入/导出Excel工具类(支持2003和2007)
- poi/jxls导入/导出Excel工具类(支持2003和2007)
- C#使用NPOI读取excel模板,并导出excel
- Birt报表导出excel(支持图片导出)
- MySQL基础(二)
- http://blog.csdn.net/csdnnews/article/details/78838714
- Java练习(5)——折半查找扩展(插入元素)
- 线程任务接口Callable使用void做为返回类型
- HAWQ安装PXF插件
- poi读取excel模板,填充内容并导出,支持导出2007支持公式自动计算
- Linux安装yarn
- 拿到标注图怎么布局?
- 仔细探讨一下Thread-safe和Async-signal safe
- re正则相关
- 1222实训
- 使用PyMySQL操作mysql数据库
- hdu 2553 经典N皇后
- Bentley LEAP Bridge Steel CONNECT Edition v17.01.00.38 Win32_64 2CD