Java 将文件表从excel文件复制到另一个文件
此java代码可以复制excel文件的工作表并将其粘贴到另一个文件中,但我在这一行有一个例外: CellStyle style=c.getCellStyle()强> 我不能粘贴样式 提前感谢您的帮助Java 将文件表从excel文件复制到另一个文件,java,Java,此java代码可以复制excel文件的工作表并将其粘贴到另一个文件中,但我在这一行有一个例外: CellStyle style=c.getCellStyle() 我不能粘贴样式 提前感谢您的帮助 FileInputStream fis=new FileInputStream(inputFile); XSSFWorkbook inputWorkbook=new XSSFWorkbook(fis); int inputSheetCount=inputWorkbook.getNumberOfSheet
FileInputStream fis=new FileInputStream(inputFile);
XSSFWorkbook inputWorkbook=new XSSFWorkbook(fis);
int inputSheetCount=inputWorkbook.getNumberOfSheets();
System.out.println("Input sheetCount: "+inputSheetCount);
File outputFile=new File("/var/opt/data/flat/sidre/talend/projects/GRDF/Reporting/tmp/WindowsPatchs/fileb.xlsx");
FileOutputStream fos=new FileOutputStream(outputFile);
XSSFWorkbook outputWorkbook=new XSSFWorkbook();
for(int i=0;i<inputSheetCount;i++)
{
XSSFSheet inputSheet=inputWorkbook.getSheetAt(i);
String inputSheetName=inputWorkbook.getSheetName(i);
XSSFSheet outputSheet=outputWorkbook.createSheet(inputSheetName);
int rowCount=inputSheet.getLastRowNum();
System.out.println(rowCount+" rows in inputsheet "+inputSheet.getSheetName());
int currentRowIndex=0;
if(rowCount>0)
{
Iterator rowIterator=inputSheet.iterator();
XSSFRow row;
while(rowIterator.hasNext())
{
int currentCellIndex=0;
row = (XSSFRow)rowIterator.next();
Iterator<Cell> cellIterator=row.cellIterator();
while(cellIterator.hasNext())
{
String cellData=cellIterator.next().toString();
Cell c = cellIterator.next();
CellStyle style = c.getCellStyle();
if(currentCellIndex==0)
{
outputSheet.createRow(currentRowIndex).createCell(currentCellIndex).setCellValue(cellData);
}
else
{
outputSheet.getRow(currentRowIndex).createCell(currentCellIndex).setCellValue(cellData);
//outputSheet.getRow(currentRowIndex).createCell(currentCellIndex).setCellStyle(style);
//outputSheet.getRow(currentRowIndex).createCell(currentCellIndex).setCellValue(cellData);
//outputSheet.getRow(currentRowIdex).createCell(currentCellIndex).setCellValue(cellData);
}
currentCellIndex++;
}
currentRowIndex++;
}
System.out.println((currentRowIndex-1)+" rows added to outputsheet "+outputSheet.getSheetName());
System.out.println();
}
}
outputWorkbook.write(fos);
// Step #10 : At the end of the Program close the FileOutputStream object.
fos.close();
```
FileInputStream fis=新文件inputstream(inputFile);
XSSF工作簿输入工作簿=新XSSF工作簿(fis);
int inputSheetCount=inputWorkbook.getNumberOfSheets();
System.out.println(“输入纸张计数:+inputSheetCount”);
File outputFile=新文件(“/var/opt/data/flat/sidre/talend/projects/GRDF/Reporting/tmp/WindowsPatchs/fileb.xlsx”);
FileOutputStream fos=新的FileOutputStream(outputFile);
XSSFWorkbook outputWorkbook=新XSSFWorkbook();
对于(int i=0;i0)
{
迭代器rowIterator=inputSheet.Iterator();
XSSFRow行;
while(roweiterator.hasNext())
{
int currentCellIndex=0;
行=(XSSFRow)行迭代器.next();
迭代器cellIterator=row.cellIterator();
while(cellIterator.hasNext())
{
字符串cellData=cellIterator.next().toString();
Cell c=cellIterator.next();
CellStyle=c.getCellStyle();
如果(currentCellIndex==0)
{
outputSheet.createRow(currentRowIndex).createCell(currentCellIndex).setCellValue(cellData);
}
其他的
{
outputSheet.getRow(currentRowIndex).createCell(currentCellIndex).setCellValue(cellData);
//outputSheet.getRow(currentRowIndex).createCell(currentCellIndex).setCellStyle(style);
//outputSheet.getRow(currentRowIndex).createCell(currentCellIndex).setCellValue(cellData);
//outputSheet.getRow(currentRowIdex).createCell(currentCellIndex).setCellValue(cellData);
}
currentCellIndex++;
}
currentRowIndex++;
}
System.out.println((currentRowIndex-1)+“添加到outputsheet的行”+outputsheet.getSheetName());
System.out.println();
}
}
输出工作簿。写入(fos);
//步骤10:在程序结束时关闭FileOutputStream对象。
fos.close();
```
是否有一个办公编程stackexchange站点可供选择?还是堆栈溢出?我在这里没有看到任何数据科学。你能粘贴你的异常堆栈跟踪吗?