我有以下格式的擅长
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;
}}}}}}
我的价值是 标题自动化主题1 标题自动化主题2
但我想在数组中捕获这些值。如何在数组中捕获这些值。我期待我的输出像这样
{Title Automaition Topic1,Title Automaition Topic2}
有人可以帮忙吗?
由于
答案 0 :(得分:0)
像这样改变你的代码......
List list = new ArrayList(); code.. .... ... if (cell.getRichStringCellValue().getString().equalsIgnoreCase("Topic")) { list.add(row.getCell(2)); break; } ... ... System.out.print("\t" + list);