1

I am using aspose.cell library in my android application to create excel sheets as an output in sdcard.

Here is my code:

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);

}

I have a set of data in arrayList, as final i need to insert that values in to a column in my worksheet. For that, i have used one for loop to get the cell position like A1,A2,A3.. from worksheet and inserting data one by one. Everything is fine, but i havent used aspose lib before so i dont know much things. Actually what i required here is, how to insert the arraylist of values directly to a Column like (A,B,C...) in excel sheet using this aspose.cell lib?

Here I ll give some links which i referred for this work.

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

I have already tried apache POI and jxl libraries, but i am feeling aspose is easy to use compared to other libs.

Rubanraj Ravichandran
  • 1,213
  • 2
  • 17
  • 26

1 Answers1

1

Aspose.Cells provides some means and data import techniques which you may try. For example, you may directly try Cells.importArrayList() method to import your underlying ArrayList to the worksheet in Excel file, see the sample code here for your reference: e.g Sample code:

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);

Please see the document for your complete reference.

I am Developer evangelist at Aspose.

Amjad Sahi
  • 1,813
  • 1
  • 10
  • 15