我有以下格式的excel
Category Name Title
Map Map1 Title Automaition Map1
Topic Topic1 Title Automaition Topic1
Topic Topic2 Title Automaition Topic2
Submap Submap1 Title Automaition Submap1
Sub Topic SubTop1 Title Automaition SubTopic1
我想将所有类别的“标题”列中的值作为“主题”并存储在数组中。我编写了以下代码,用于将“类别”的“标题”列中的值用作“主题”
public class DitaExcel {
@Test
public void Test() throws IOException {
{
FileInputStream file = new FileInputStream(new File("C://DitaExchange.xlsx"));
//Create Workbook instance holding reference to .xlsx file
XSSFWorkbook workbook = new XSSFWorkbook(file);
//Get first/desired sheet from the workbook
XSSFSheet sheet = workbook.getSheetAt(0);
for (Row row : sheet) {
for (Cell cell : row) {
CellReference cellRef = new CellReference(row.getRowNum(), cell.getColumnIndex());
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
if (cell.getRichStringCellValue().getString().equalsIgnoreCase("Topic"))
{
System.out.println(row.getCell(2));
break;
}
break;
}}}}}}
我得到的值是Title Automaition Topic1 Title Automaition Topic2
但是我想在数组中捕获这些值。如何捕获数组中的这些值。我希望我的输出是这样的
{标题自动标题1,标题自动标题2}
有人可以帮忙吗?
谢谢
像这样更改您的代码...
列表列表= new ArrayList(); 代码.. .... ... 如果(cell.getRichStringCellValue()。getString()。equalsIgnoreCase(“ Topic”)) { list.add(row.getCell(2)); 休息; } ... ... System.out.print(“ \ t” +列表);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句