DataTable as DataSource for WorkbookDesigner

Hey Aspose-Team/Community,
I’ve tried to load data from a SQL-Table and put it into an excel-sheet. As far as good, but now I wanted to define a layout for the generated excel-file. I’ve created a template and saved it on my pc. For the next step I loaded the data to a DataTable and want to publish the data to the Workbook but there is no Data transmitted. I found an example of you which were quite similar to my needs but you have to create a custom class which represents the Data I want to fetch and since my application should be dynamic I can’t create custom classes (although with that class it were successfull).

The Code-Snippet:
// Instantiating a WorkbookDesigner object
WorkbookDesigner designer = new WorkbookDesigner();

// Open a designer spreadsheet containing smart markers
designer.Workbook = wb;

DataTable tab = new DataTable();

// Create DataAdapter
SqlDataAdapter da = new SqlDataAdapter(cmd);
// query the result of the SQL to the DataTable
da.Fill(tab);

// Set the DataSource for the Designer spreadsheet
designer.SetDataSource(“ExcelTest”, tab);

// Process the smart markers
designer.Process();

The result of the SQL-Query is not empty and of course I do save the file afterwards.

@t.eickelmann

Thanks for your posting and using Aspose APIs.

We have uploaded a

for your reference. It uses the most recent version. Please download it and execute at your end. It also contains Sample Excel File With Smart Markers and when you will execute the project, it will generate Output Excel File.

Download Links
sampleSmartMarkerTest.zip (6.8 KB)
outputSmartMarkerTest.zip (7.9 KB)

1 Like

@shakeel.faiz
Thank you very much for your fast reply and I apologize for my delayed response.

The solution fits exactly to my needs! :slight_smile:

Best regards,
Tim

@t.eickelmann

Thanks for your feedback. It is good to know that it fits your needs. : )

If you face any issue, please feel free to let us know, we will be glad to look into it and help you further.