Open xlsx file as template- add rows then save it to another file

Dear All,


I have a xlsx file and I want to open it as template then add data into it and then save to another file, so the it would be always empty…

could any body please help… how to open excel file and add some rows then save it to another file…?

many thanks in advance

Regards
Win

Hi Win,

Thanks for your posting and considering Aspose.Cells.

You can create a template file in MS-Excel and then load it in a Workbook object using Aspose.Cells. Then whatever changes you will do with the Workbook object will not affect your template file. Then you can save your Workbook object into some other Excel file.

Please see the following code. It loads a template file which was created with MS-Excel, then it adds some data inside it using Aspose.Cells and then saves the workbook object as output file. As you can see, output file looks like a template file with some data inside it but there is nothing changed in the template file.

I have attached the template file, output file and screenshot showing the outcome for your reference.

C#


//Load your template file inside a workbook object

Workbook workbook = new Workbook(“template.xlsx”);


//Access the first worksheet

Worksheet worksheet = workbook.Worksheets[0];


//Add some data inside the cells

for (int i = 1; i < 9; i++)

{

Cell cell = worksheet.Cells[i, 0];

cell.PutValue(“Test-” + i);


cell = worksheet.Cells[i, 1];

cell.PutValue(i);

}


//Save the workbook object as an output file

workbook.Save(“output.xlsx”);