Exceptions when Cells.ImportDataTable(dataTable- true-"A1");

I got exception on cells when ImportDataTable to cells. The following code I copy from the Demo. I got the exception like that.


BoolValue = ‘(workbook.Worksheets[0].Cells).FirstCell.BoolValue’ threw an exception of type 'Aspose.Cells.CellsException’

base {System.ApplicationException} = {“Cell value type is not booleanin CellC3”}
 DataTable dataTable = new DataTable(“Products”);
        <span style="color:green;">//Adding columns to the DataTable object</span>
        dataTable.Columns.Add(<span style="color:#a31515;">"Product ID"</span>, <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">Int32</span>));
        dataTable.Columns.Add(<span style="color:#a31515;">"Product Name"</span>, <span style="color:blue;">typeof</span>(<span style="color:blue;">string</span>));
        dataTable.Columns.Add(<span style="color:#a31515;">"Units In Stock"</span>, <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">Int32</span>));

        <span style="color:green;">//Creating an empty row in the DataTable object</span>
        <span style="color:#2b91af;">DataRow</span> dr = dataTable.NewRow();

        <span style="color:green;">//Adding data to the row</span>
        dr[0] = 1;
        dr[1] = <span style="color:#a31515;">"Aniseed Syrup"</span>;
        dr[2] = 15;

        <span style="color:green;">//Adding filled row to the DataTable object</span>
        dataTable.Rows.Add(dr);

        <span style="color:green;">//Creating another empty row in the DataTable object</span>
        dr = dataTable.NewRow();

        <span style="color:green;">//Adding data to the row</span>
        dr[0] = 2;
        dr[1] = <span style="color:#a31515;">"Boston Crab Meat"</span>;
        dr[2] = 123;

        <span style="color:green;">//Adding filled row to the DataTable object</span>
        dataTable.Rows.Add(dr);


        <span style="color:#2b91af;">Workbook</span> workbook = <span style="color:blue;">new</span> <span style="color:#2b91af;">Workbook</span>();

                   
        <span style="color:green;">// Import data from the DataTable and create a stacked area chart from it.</span>
        workbook.Worksheets[0].Cells.ImportDataTable(dataTable, <span style="color:blue;">true</span>,<span style="color:#a31515;">"A1"</span>);</pre></div></div>

Hi,

Please download and use the latest version:

It is working fine.

Please see the following code and the output file generated by it which I have attached with this post.

C#


DataTable dataTable = new DataTable(“Products”);


//Adding columns to the DataTable object

dataTable.Columns.Add(“Product ID”, typeof(Int32));

dataTable.Columns.Add(“Product Name”, typeof(string));

dataTable.Columns.Add(“Units In Stock”, typeof(Int32));


//Creating an empty row in the DataTable object

DataRow dr = dataTable.NewRow();


//Adding data to the row

dr[0] = 1;

dr[1] = “Aniseed Syrup”;

dr[2] = 15;


//Adding filled row to the DataTable object

dataTable.Rows.Add(dr);


//Creating another empty row in the DataTable object

dr = dataTable.NewRow();


//Adding data to the row

dr[0] = 2;

dr[1] = “Boston Crab Meat”;

dr[2] = 123;


//Adding filled row to the DataTable object

dataTable.Rows.Add(dr);



Workbook workbook = new Workbook();


// Import data from the DataTable and create a stacked area chart from it.

workbook.Worksheets[0].Cells.ImportDataTable(dataTable, true, “A1”);



//Save your workbook

workbook.Save(“output.xlsx”);