简体   繁体   English

如何在Java中使用POI在不同的列上写入现有的Excel(* .xlsx)文件?

[英]How to write existing excel (*.xlsx) file on different column using POI in Java?

Dear all member here!! 亲爱的所有会员!

I got a problem that need to ask your help. 我有一个问题需要向您寻求帮助。 I already have an excel file (sample.xlsx). 我已经有一个excel文件(sample.xlsx)。 I need to use java code for appending my old data. 我需要使用Java代码附加我的旧数据。

Here is my specifications: 这是我的规格:

  1. My old data is in column A, 100 rows for example. 我的旧数据在A列中,例如100行。
  2. Need to write other data (50 rows) in different column, column B for example. 需要在其他列(例如B列)中写入其他数据(50行)。
  3. Appending data is also start from first row as the old data. 追加数据也从第一行开始作为旧数据。

Is it possible to do that in POI? 是否可以在POI中做到这一点?

Here is what you need to do. 这是您需要做的。

XSSFSheet sheet = workbook.getSheet("sample");
for(int i=0; i<numberOfRowsToWriteDataIn; i++) {
   XSSFRow row = sheet.getRow(i);
   row.createCell(5).setCellValue("Creation Date: "+ new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
}

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM