import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;


import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

	
public class parseToExcel {
	/**
	 * POI 修改 2003版本以上的Excel
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		
		 //excel模板路径  
        File fi=new File("F:/模板文件.xlsx");  
        //读取excel模板  
        Workbook wb = WorkbookFactory.create(new FileInputStream(fi));
        //读取了模板内所有sheet内容  0表示Excel 中的第一页内容 以此类推
        Sheet sheet = wb.getSheetAt(0);  
        //给相应的单元格进行赋值  
        //注意如果Excel是一个空的Excel文件,
         //那么获得Row 和 Cell 的方法是 Row row =  sheet.createRow(0);  Cell cell = row.createCell(0);
        Cell cell = sheet.getRow(6).getCell(0);  
        cell.setCellValue("第七行第一列值修改");  
        Cell cell2 = sheet.getRow(5).getCell(5);
        cell2.setCellValue("第六行的第6列值修改");
        Cell cell3 = sheet.getRow(3).getCell(3);
        cell3.setCellValue("第四行的第四列的值进行了修改");
        //修改模板内容导出新模板  
        FileOutputStream out = new FileOutputStream("F:/更新后的文件.xlsx");  
        wb.write(out);  
        out.close();
		
        
        
        
   	 //excel模板路径  
//        File fi=new File("F:/logen.xlsx");  
//        POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(fi));  
//        //读取excel模板  
//        HSSFWorkbook wb = new HSSFWorkbook(fs);  
//        //读取了模板内所有sheet内容  
//        HSSFSheet sheet = wb.getSheetAt(0);  
//        //在相应的单元格进行赋值  
//        HSSFCell cell = sheet.getRow(1).getCell(3);  
//        cell.setCellValue("测试");  
//        HSSFCell cell2 = sheet.getRow(3).getCell(3);  
//        cell2.setCellValue("数据");  
//        HSSFCell cell3 = sheet.getRow(0).getCell(0);  
//        cell3.setCellValue("大标题");    
//        //修改模板内容导出新模板  
//        FileOutputStream out = new FileOutputStream("F:/logentext.xlsx");  
//        wb.write(out);  
//        out.close();
        
       
	}
}
最近下载更多
爱情戴罪的羔羊  LV7 2023年10月27日
WangChuanGuo0421  LV1 2022年2月9日
zhuohanyuan  LV10 2021年12月30日
可可西里的乐乐  LV4 2021年10月11日
banliyoo  LV2 2021年9月16日
爱自己的修罗  LV7 2020年9月29日
星海无垠  LV2 2020年7月16日
乐观的21啊  LV2 2020年6月18日
babyFF9  LV8 2020年6月10日
ym1997  LV1 2020年4月20日
最近浏览更多
爱情戴罪的羔羊  LV7 2023年10月27日
Eddie233  LV5 2023年6月14日
可是不知道么  LV23 2023年5月6日
deluser  LV3 2022年11月16日
微信网友_6040315240812544  LV8 2022年10月20日
萌新不想挨打 2022年9月4日
暂无贡献等级
是你爸爸啊100  LV5 2022年8月8日
3199625134  LV10 2022年5月19日
WangChuanGuo0421  LV1 2022年2月9日
zhuohanyuan  LV10 2021年12月30日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友