乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > java <em>poi</em>读取excel数据怎么是修改之前呢,打开ex...-java操

java <em>poi</em>读取excel数据怎么是修改之前呢,打开ex...-java操

作者:乔山办公网日期:

返回目录:excel表格制作


public SXSSFWorkbook(XSSFWorkbook workbook)

  • Construct a workbook from a template.

    There are three use-cases to use
    SXSSFWorkbook(XSSFWorkbook) :

  • Append new sheets to existing workbooks. You can open existing workbook from
    a file or create on the fly with XSSF.

  • Append rows to existing sheets. The row number MUST be greater than
    max(rownum) in the template sheet.

  • Use existing workbook as a template and re-use global objects such as cell
    styles, formats, images, etc.

  • All three use cases can work in a
    combination. What is not supported:

  • Access initial cells and rows in the template. After constructing SXSSFWorkbook(XSSFWorkbook) all internal windows are empty and SXSSFSheet.getRow(int) and SXSSFRow.getCell(int) return null.

  • Override existing cells and rows. The API silently allows that but the
    output file is invalid and Excel cannot read it.

API文档e79fa5e98193e78988e69d83333里面有,反正就是说,使用SXSSFWorkbook附加数据到已经存在的Excel中的话就是不行的;SXSSFSheet.getRow(int) 和 SXSSFRow.getCell(int) 会返回空。

SXSSFWorkbook只能用在新创建Excel中才行。



这说明你读表的表路径出了问题,虽然是同一张表,但是你把表复制到其他地方再进行修改当然不会更新


修改完需636f7079e799bee5baa6e79fa5e98193333要写入,也就是保存一下的。
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class ChangeCell {

@SuppressWarnings("deprecation")
public static void main(String[] args) {
String fileToBeRead = "C:\\exp.xls"; // excel位置
int coloum = 1; // 比如你要获取第1列
try {
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(
fileToBeRead));
HSSFSheet sheet = workbook.getSheet("Sheet1");

for (int i = 0; i <= sheet.getLastRowNum(); i++) {
HSSFRow row = sheet.getRow((short) i);
if (null == row) {
continue;
} else {
HSSFCell cell = row.getCell((short) coloum);
if (null == cell) {
continue;
} else {
System.out.println(cell.getNumericCellValue());
int temp = (int) cell.getNumericCellValue();
cell.setCellValue(temp + 1);
}
}
}
FileOutputStream out = null;
try {
out = new FileOutputStream(fileToBeRead);
workbook.write(out);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}

}

相关阅读

  • -java poi excel模板,java使用poi读取excel

  • 乔山办公网excel表格制作
  • 需要导入jxl.jar (在网上可以下载,然后放到lib文件夹中)开放分类: java通过java操作excel表格的工抄具类库支持Excel 95-2000的所有版本生成Excel 2000标准格式支持字体、数字、日期操作 能够
关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网