Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid output to Excel opens in Browser itself.

Status
Not open for further replies.

ravula2000

IS-IT--Management
Mar 8, 2002
205
0
0
US
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)

hw.RenderBeginTag("h5")
hw.Write("Case# " & lsCaseNum)
hw.RenderEndTag
fdgdcardslawenf.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()

The above code opens in a browser in excel... But I want to open Excel application and it should prompt in which directory i want to save and then it should save accordingly..

Thanks
Srini
 
This is how you open an excel app in c#. Make sure you add the ref to the excel obj.

object format=5;
Excel.ApplicationClass xlApp=new Excel.ApplicationClass();
Excel.Workbook xlBook=xlApp.Workbooks.Open(@"F:\Book1.XLS",0, false, format, null, null, false, Excel.XlPlatform.xlWindows, null,true, false, 0, true, false, false);
Excel.Sheets xlSheets = xlBook.Worksheets;
Excel.Worksheet xlSheet = (Excel.Worksheet)xlSheets.get_Item("Sheet1");
xlSheet.Cells[1,2]="blah";

xlBook.Save();
xlApp.Quit();

This is vb I think. Still testing it.

Dim format As Object = 5
Dim xlApp As New Excel.ApplicationClass
Dim xlBook As Excel.Workbook = xlApp.Workbooks.Open("")
Dim xlSheets As Excel.Sheets = xlBook.Worksheets


Dim xlSheet As Excel.Worksheet = CType(xlSheets.Item("Sheet1"), Excel.Worksheet)
xlSheet.Cells(1, 2) = "blah"

xlBook.Save()
xlApp.Quit()

The save as dialog I haven't seen. I know that when you go to X out of excel when it is in the browser it asks you if you want to save it.

HTH

Chad
 
stick this in to save as..

vb...

xlapp.SaveWorkspace(FileName:="c:\book1.xls")
 
It doesnt matter how you create the spreadsheet wether it by changing the content-type or using Office Automation as henslecd has done the result is the same when it is returned to the client via http.

Wether the spreadsheet opens in the browser using a plug-in or the excel application is determined by the Internet settings on the client computer. Unfortunately unless you are developing for a strictly controlled corporate intranet you cannot gaurentee these settings.

Rob

Go placidly amidst the noise and haste, and remember what peace there may be in silence - Erhmann 1927
 
I got the solution.
In Windows Explorer I went to Tools->Folder Options->FileTypes.
I selected XLS filetype and clicked on Advanced and Unchecked 'Browse in same window'.
Now the excel output is opening with Excel application, so that I can able to save the file to my hard drive

Thanks for giving me so many ideas.

I appreciate your help.

Srini
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top