【问题标题】:How to insert a list of values in a column in excel sheet using aspose library in android?如何使用android中的aspose库在excel表的列中插入值列表?
【发布时间】:2015-07-01 07:21:42
【问题描述】:

我在我的 android 应用程序中使用 aspose.cell 库来创建 excel 工作表作为 sdcard 中的输出。

这是我的代码:

void insertData() throws Exception {

    //Get the SD card path
    String sdPath = Environment.getExternalStorageDirectory().getPath() + File.separator;

    Workbook wb = new Workbook();

    Worksheet worksheet = wb.getWorksheets().get(0);

    Cells cells = worksheet.getCells();

    ArrayList<String> arr = new ArrayList<String>();
    arr.add("one");
    arr.add("two");
    arr.add("three");

    int i = 0;
    for(String value : arr){
        //Put some values into cells
        //Log.i("rubanraj", value);
        Cell cell = cells.get("A"+String.valueOf(++i)); //for A1,A2,A3...
        cell.putValue(value);
    }

    wb.save(sdPath + "Cells_InsertRowsAndColumns.xlsx",SaveFormat.XLSX);

}

我在 arrayList 中有一组数据,最后我需要将这些值插入到我的工作表的列中。为此,我使用了一个 for 循环从工作表中获取单元格位置,如 A1、A2、A3 .. 并一一插入数据。 一切都很好,但我之前没有使用过 aspose lib,所以我不太了解。实际上我在这里需要的是,如何使用这个 aspose.cell 库将值的数组列表直接插入到 Excel 表中的 (A,B,C...) 之类的列中?

在这里,我将提供一些我为这项工作参考的链接。

https://github.com/asposecells/Aspose_Cells_Android/blob/master/Examples/QuickStart/InsertRowsAndColumns/src/com/example/insertrowsandcolumns/MainActivity.java

https://github.com/asposecells/Aspose_Cells_Android

我已经尝试过 apache POI 和 jxl 库,但我觉得 aspose 与其他库相比更易于使用。

【问题讨论】:

    标签: android aspose aspose-cells


    【解决方案1】:

    Aspose.Cells 提供了一些您可以尝试的方法和数据导入技术。例如,您可以直接尝试 Cells.importArrayList() 方法将您的底层 ArrayList 导入 Excel 文件中的工作表,请参阅此处的示例代码供您参考: 例如 示例代码:

    Workbook wb = new Workbook();
    
    Worksheet worksheet = wb.getWorksheets().get(0);
    
    Cells cells = worksheet.getCells();
    
    ArrayList<String> arr = new ArrayList<String>();
    arr.add("one");
    arr.add("two");
    arr.add("three");
    
    //Importing the contents of ArrayList vertically (A1:A3).
    cells.importArrayList(arr,0,0,true);
    
    //Importing the contents of ArrayList horizontally (A10:C10).
    cells.importArrayList(arr,9,0,false);
    

    请参阅document 以获取完整参考。

    我是 Aspose 的开发布道者。

    【讨论】:

    • 嘿,谢谢你的回答。我会试试这个让你知道状态。
    • 文档参考链接已失效
    猜你喜欢
    • 1970-01-01
    • 2023-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多