我写了一个用于在 Excel 表中写入数据的代码。在此我必须在多个单元格中写入数据。但它显示了一些错误。对于一个单元格,它能够更改数据。我保留for 循环以更改数据在多个单元格中。为此,它显示错误。谁能告诉我我在哪里做错了。
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import java.lang.String;
import javax.swing.JOptionPane;
import jxl.Cell;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.ss.formula.functions.Column;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFComment;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class Sele1
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
String FileName = "C:\\Users\\u304081\\Desktop\\Java\\new.xlsx";
try
{
FileInputStream fileInputStream3 = new FileInputStream(FileName);
File outputsheetfile1 = new File(FileName);
if(outputsheetfile1.exists())
{
System.out.println("File existed");
try
{
XSSFWorkbook ObjWorkBook = new XSSFWorkbook(fileInputStream3);
XSSFSheet DriverTableSheet = ObjWorkBook.getSheetAt(0);
for(int i=1;i<3;i++)
{
XSSFRow row1 = DriverTableSheet.getRow(i);
XSSFCell Cell1 = row1.getCell(0);
System.out.println("Cell1"+ Cell1);
//System.out.println("Cell2"+ Cell2);
String str = "Abc";
Cell1.setCellValue(str);
FileOutputStream out1 = new FileOutputStream (FileName,false);
ObjWorkBook.write(out1);
fileInputStream3.close();
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我得到的错误是:
ObjWorkBook.write(out1);
`"poi-bin-3.9-20121203\poi-3.9\poi-ooxml-3.9-20121203.jar has no source attachment"`