Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 Restaurants
{
get
{
if (ViewState[ViewstateRestaurantName] != null)
{
object o = ViewState[ViewstateRestaurantName]
return (Collection)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 2-May-13 18:15pm
Comments
Sergey Alexandrovich Kryukov at 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)

  Print Answers RSS
0 OriginalGriff 7,800
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 2 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100