We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose cells display first row from datasource (Datatable)

Hi,

I am using Aspose.cells for .net.

I have a requirement where my datasource contains a column that contains the same value in all the rows.

That value is the report heading.

I want to use that value to indicate the report heading.

In other words just want to use the value in the first row and display it in a cell in the aspose output



Regards,
Manesh M

Hi Manesh,

Thanks for your posting and using Aspose.Cells.

Please clarify your requirements more. You can provide us your actual output Excel file and the expected output Excel file which you can generate manually using MS-Excel and post it here for our reference.

It will help us look into your issue more closely and precisely and we will be able to help you asap.

Also, if you could provide us your sample code, it will also be helpful for us to investigate this issue.

Hi,

The requirement is I would have the below table as the data source

ColumnName1 ColumnName2 ColumnName3 Report Heading
Column1Value1 Column2Value1 Column3Value1 abc
Column1Value2 Column2Value2 Column3Value2 abc
Column1Value3 Column2Value3 Column3Value3 abc
Column1Value4 Column2Value4 Column3Value4 abc
Column1Value5 Column2Value5 Column3Value5 abc
Column1Value6 Column2Value6 Column3Value6 abc
Column1Value7 Column2Value7 Column3Value7 abc
Column1Value8 Column2Value8 Column3Value8 abc
Column1Value9 Column2Value9 Column3Value9 abc
Column1Value10 Column2Value10 Column3Value10 abc
Column1Value11 Column2Value11 Column3Value11 abc
Column1Value12 Column2Value12 Column3Value12 abc
Column1Value13 Column2Value13 Column3Value13 abc
Column1Value14 Column2Value14 Column3Value14 abc

The above table is just a representation of a table fetched from database.
Here,
"ColumnName1", "ColumnName2", "ColumnName3", "Report Heading" are the column headings

Value in "Report Heading" column should be displayed just once as the report heading.
Please refer to the attachment that contains a value named "abc"

Hi Manesh,

Thanks for your posting and using Aspose.Cells.

You can set the report heading using the variable. Please check the attached smart marker file for your reference.

There you will find

&=$ReportHeading

and in the following code you will see this code.

//Set the report heading using variable
designer.SetDataSource(“ReportHeading”, reportHeading);

Please see the following complete runnable code. I have also attached the output Excel file generated by it for your reference.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\DynamicReportHeading.xlsx”;


Workbook workbook = new Workbook(filePath);


Worksheet data = workbook.Worksheets[“DatatableName”];


DataTable dt = data.Cells.ExportDataTable(5, 1, 15, 4, true);

dt.TableName = “DatatableName”;


//Get the report heading inside the variable

string reportHeading = dt.Rows[0][“Report Heading”] as string;


WorkbookDesigner designer = new WorkbookDesigner(workbook);

designer.SetDataSource(dt);


//Set the report heading using variable

designer.SetDataSource(“ReportHeading”, reportHeading);


designer.Process();


workbook.Save(filePath + “.out.xlsx”);

Thanks for your reply.

I considered that as a possible approach.

However, just wanted to understand if we can just get the first value of a column and display it as a heading using aspose smart marker syntax.

Hi Manesh,

Thanks for your posting and using Aspose.Cells.

You cannot just take a single value from column and leave the entire column. It is not possible. You will have to read the single value in a variable first and then set the report heading using the variable with the approach shown to you in above post.