Skip to content

Commit

Permalink
Adjust sample-code somewhat to show in the ui that we can write and r…
Browse files Browse the repository at this point in the history
…ead data from .xlsx-files
  • Loading branch information
centic9 committed Mar 8, 2017
1 parent a329faf commit 09278e7
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import android.os.Bundle;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.dstadler.poiandroidtest.poitest.dummy.DummyContent;

import java.io.*;
import java.util.Map;


/**
Expand Down Expand Up @@ -50,7 +52,11 @@ protected void onCreate(Bundle savedInstanceState) {
Sheet sheet = wb.createSheet("Sheet1");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("testvalue");
cell.setCellValue("cell-1");
cell = row.createCell(1);
cell.setCellValue("cell-2");
cell = row.createCell(2);
cell.setCellValue("cell-3");

OutputStream stream = openFileOutput("test.xlsx", Context.MODE_PRIVATE);
try {
Expand All @@ -63,6 +69,16 @@ protected void onCreate(Bundle savedInstanceState) {

InputStream input = openFileInput("test.xlsx");
wb = WorkbookFactory.create(input);

// replace the dummy-content to show that we could write and read the cell-values
int i = 0;
row = wb.getSheetAt(0).getRow(0);
for (Map.Entry<String, DummyContent.DummyItem> entry : DummyContent.ITEM_MAP.entrySet()) {
entry.getValue().content = row.getCell(i).getStringCellValue();

i++;
}

wb.close();
} catch (Exception e) {
throw new IllegalStateException(e);
Expand Down

0 comments on commit 09278e7

Please sign in to comment.