Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am doing a project regarding Hotel Management System. In this project I am using ViewStates to store data within pages. Now I want to generate a Excel document(xls) by using the data stored in ViewState. I have stored the data into ViewState using Collections.

This is the code for the view state

protected Collection<restaurantresponsedto> Restaurants
{
get
{
if (ViewState[ViewstateRestaurantName] != null)
{
object o = ViewState[ViewstateRestaurantName]
return (Collection<restaurantresponsedto>)o
}
else
{
return null
}

}

set
{
ViewState[ViewstateRestaurantName] = value
}
}


And this is my Excel generation codes.

protected void Button1_Click(object sender, EventArgs e)
{
////RestaurantRequestDto restaurant = new RestaurantRequestDto()

Application xlapp = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Application")
Workbook xlworkbook = (Workbook)xlapp.ActiveWorkbook
Worksheet xlworksheet = (Worksheet)xlworkbook.ActiveSheet

xlworkbook.SaveAs("csharp-Excel.xls", XlFileFormat.xlWorkbookNormal, XlSaveAsAccessMode.xlExclusive)
Range chart_range = xlworksheet.UsedRange
for (int i = 0 i < Restaurants.Count-1 i++)
{
for (int j = 0 j < 5 j++)
{
xlworksheet.Cells[i + Restaurants.Count, j + 1] = this.Restaurants.FirstOrDefault()
}
}

}


Your kind assistance will be appreciated.
Thanks in advance.
Posted
Comments
Sergey Alexandrovich Kryukov 3-May-13 0:06am    
Not a question, not clear what help would you expect.
—SA

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