如何在Android中创建xls工作表并向其中添加动态数据?

如何在Android中创建xls工作表并向其中添加动态数据?,android,Android,这是我的代码,我希望每次动态添加从EditText获取的数据 //New Workbook Workbook wb = new HSSFWorkbook(); Cell c = null; //Cell style for header row CellStyle cs = wb.createCellStyle(); cs.setFillForegroundColor(HSSFColor.LIME.index); cs.setFillPattern(HSSFCellStyle.SOLID_F

这是我的代码,我希望每次动态添加从
EditText
获取的数据

//New Workbook
Workbook wb = new HSSFWorkbook();

Cell c = null;

//Cell style for header row
CellStyle cs = wb.createCellStyle();
cs.setFillForegroundColor(HSSFColor.LIME.index);
cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

//New Sheet
Sheet sheet1 = null;
sheet1 = wb.createSheet("MYtest");

// Generate column headings
Row row1=sheet1.createRow(0);
c = row1.createCell(0);
c.setCellValue("ENTRY ONE");
c.setCellStyle(cs);

c = row1.createCell(1);
c.setCellValue("ENTRY TWO");
c.setCellStyle(cs);

c = row1.createCell(2);
c.setCellValue("ENTRY THREE");
c.setCellStyle(cs);

您必须使用ApachePOI。 下载ApachePOIJAR文件或

将行添加到渐变文件中

 compile 'org.apache.poi:poi:3.9'
并创建、读取、写入excel文件


下面是供您参考的示例教程

如果要使用在
EditText
中输入的数据动态修改单元格值,应使用“TextWatcher”设置单元格中的文本。见下例:

editText.addTextChangedListener(new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {
        row1.getCell(1).setCellValue(s.toString());
    }
});

尽管如此,根据您对XLS文件的可视化方式,更改不能被认为是动态的,因为您必须导出文档然后查看它。

您应该细分或缩小问题的范围。您的问题是创建XLS文件还是构建Android GUI以检索用户输入?