我有以下代码块:
File file = new File("myFile.xlsx"); // my file
inputStream = new FileInputStream(file);
System.out.println("reading");
XSSFWorkbook wb = new XSSFWorkbook(inputStream);
XSSFSheet sh = wb.getSheetAt(0); // first sheet
Iterator rowIter = sh.rowIterator();
while(rowIter.hasNext()){ // iterate over all rows
System.out.println("New Row "); // notify of new row
Row myRow = (Row) rowIter.next();
Iterator cellIter = myRow.cellIterator();
while(cellIter.hasNext()){ // iterate over all cells in row
XSSFCell myCell = (XSSFCell) cellIter.next();
//how can I check that myCell has an image?
//(I'm expecting it to be in the fourth cell each time)
System.out.print(" " + myCell); // output cell content on same line
}
}
inputStream.close();
我正在使用 Apache POI 读取 .xlsx 文件。每行可以包含一个带有用户粘贴到其中的图像的单元格。
我希望抓取图像并将其编码为base64。如何在遍历电子表格时检查单元格是否包含图像?
我已经阅读了http://poi.apache.org/spreadsheet/quick-guide.html#Images,但这涉及首先获取所有图像,然后遍历它们。我想遍历单元格并检查图像。