Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear frnds,
How to open excel worksheet on aspose cell in existing excel template and write new excel worksheets on existing excel template using asp.net with c#?

Thanks and regards,
Parthiban K.
Posted
Updated 28-Apr-14 1:46am
v2

If I understand what you are asking, you want to add a new worksheet to an Excel document using Aspose?

C#
var workbook = new Workbook("C:\\Project\\Test.xlsx");
workbook.Worksheets.Add("New Worksheet");

var newWorksheet = workbook.Worksheets["New Worksheet"];
//From this point you can do what you need too with the new worksheet

workbook.Save("C:\\Project\\New.xlsx", SaveFormat.Xlsx);
 
Share this answer
 
Comments
Parthi_Karnan 28-Apr-14 23:56pm    
mostly correct but the question is i already had one excel template( It contains two worksheets, Example: "Test.xlsx") then i have to write one new worksheet like "New.xlsx"(It's a worksheet name) from the dataset on the same template: "Test.xlsx" . after write the dataset values on the excel template, the template name will be save as "Test_D1234_00.xlsx".<br>
Here how can i write the dataset vlues on the Excel template like "Test.xlsx" using asp.net with c# ?<br>
 <br>
Thanks and regards,<br>
Parthiban K.
AnvilRanger 30-Apr-14 8:54am    
From your example my solution is correct. You just add a 3rd worksheet to the Excel document like I stated in my solutions. Then do your dump from your dataset and then save as a new excel document.
Dear frnds,

I found the correct answer to this question, here that code:

.aspx.cs



C#
public void AllTabExport(DataTable dt, String sheetname)
    {
        string jobno = ddlno.SelectedItem.Text;
        string jobrevno = ddlRevNo.SelectedItem.Text;
        Aspose.Cells.License Lic = new Aspose.Cells.License();
        Lic.SetLicense("Aspose.Cells.lic");
        //Instantiate a new Workbook
        Workbook workbook = new Workbook();
        workbook.Worksheets.Clear();
        //Add a new Sheet "Data";
        workbook.Open(Server.MapPath(".") + @"\Report\Model-Template.xls");
        Worksheet worksheet = workbook.Worksheets.Add("GAD_Model_Template");
        DataRow dr = dt.NewRow();
        dt.Rows.Add(dr);
        worksheet.Cells.ImportDataTable(dt, true, "A1");
        workbook.Save(Server.MapPath(".") + @"\Report\GAD_Model_Template_" + Convert.ToString(Session["UID"]) + "_" + jobno + "_" + jobrevno + ".xls");
        ScriptManager.RegisterStartupScript(this, GetType(), "", "alert('Data has been sucessfully expored');", true);
    }


Thanks for your kind coordination Smile !



Thanks and regards,

Parthiban K.
 
Share this answer
 
Use FREE Opensource EPPlus Library.

http://epplus.codeplex.com

Which version of .net framework are you targeting?
 
Share this answer
 
Comments
Parthi_Karnan 28-Apr-14 23:45pm    
3.5 framework....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900