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

Free Support Forum - aspose.com

Why does this code produce nothing?

    Taken directly from the example code:

    public void CreateSpreadsheet()
    {
        DataTable dtStudent = new DataTable("Student");

        // Define a field in it
        DataColumn dcName = new DataColumn("Name", typeof(string));
        dtStudent.Columns.Add(dcName);

        // Add three rows to it
        DataRow drName1 = dtStudent.NewRow();
        DataRow drName2 = dtStudent.NewRow();
        DataRow drName3 = dtStudent.NewRow();

        drName1["Name"] = "John";
        drName2["Name"] = "Jack";
        drName3["Name"] = "James";

        dtStudent.Rows.Add(drName1);
        dtStudent.Rows.Add(drName2);
        dtStudent.Rows.Add(drName3);

        Workbook wb = new Workbook();

        WorkbookDesigner wd = new WorkbookDesigner();
        wd.SetDataSource(dtStudent);
        wd.Workbook = wb;
        wd.Process();

        //wd.Workbook.Save(@"C:\temp\123.xls"); // Does nothing either
        wb.Save(@"C:\temp\123.xls");
    }

The file is created, with nothing in the spreadsheet. Pls explain what I’m doing wrong.
Using v18.7

@Dork.Scott,

Thanks for your query. It seems that you have used sample which is used for importing data and filling an Excel sheet with smart markers. You may please use following sample code to import data from DataTable into Excel file.

// Instantiating a Workbook object            
Workbook workbook = new Workbook();

// Obtaining the reference of the worksheet
Worksheet worksheet = workbook.Worksheets[0];

// Instantiating a "Products" DataTable object
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);

// Importing the contents of DataTable to the worksheet starting from "A1" cell,
// Where true specifies that the column names of the DataTable would be added to
// The worksheet as a header row
worksheet.Cells.ImportDataTable(dataTable, true, "A1");

// Saving the Excel file
workbook.Save(path + "DataImport.out.xls");

For more details about importing data into Excel file, please visit the following article.

Import data into worksheet

@Dork.Scott,

You are missing the core thing. Seeing your following code segment, it looks you are processing Smart Markers using the relevant APIs. But you have not specified the Smart Markers tag either using your template file or insert them dynamically in the code.
e.g
Sample code:

WorkbookDesigner wd = new WorkbookDesigner();
wd.SetDataSource(dtStudent);
wd.Workbook = wb;
wd.Process();

Either you should have a template Excel file containing a Smart Marker, such as, “&=Student.Name” (in A1 or any other cell in the sheet) which you will open via the statement like:
Workbook wb = new Workbook("Book1.xlsx");
Or you need to add a line of code to add the marker dynamically:
e.g
Sample code:

Workbook wb = new Workbook();
wb.Worksheets[0].Cells[“A1”].PutValue("&=Student.Name");
WorkbookDesigner wd = new WorkbookDesigner();
wd.SetDataSource(dtStudent);
wd.Workbook = wb;
wd.Process();

Please see the document on how to use Smart Markers for your reference:
https://docs.aspose.com/display/cellsnet/Using+Smart+Markers

Let us know if you still have any issue or confusion.