开发者

How to open savedialogbox in excel from .net windows form

开发者 https://www.devze.com 2023-01-08 07:52 出处:网络
I have created an a开发者_如何转开发pplication in vb.net from this application i want to open excel file with excel\'s saveAs option. Is there any way i can do this?

I have created an a开发者_如何转开发pplication in vb.net from this application i want to open excel file with excel's saveAs option. Is there any way i can do this?

thanx


I am not sure how you can do this prior to Office 2007, but in 07 onwards there is an Application.GetSaveAsFilename() method which pops up a save as dialog.

Something like this might do what you want (in C#):

        var app = new Microsoft.Office.Interop.Excel.Application();
        app.Visible = true;

        var book = app.Workbooks.Open(@"I:\ApplicationsUAT\PriceGrab\PriceCheck.xls");
        book.Names.Item("dt").RefersToRange.Value = DateTime.Today.ToOADate();
        app.CalculateFull();

        object fld = app.GetSaveAsFilename(FileFilter:"Microsoft Office Excel Workbook (*.xls), *.xls");
        if (fld is string)
            book.SaveAs((string)fld, Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel12);
        book.Close(false);

        app.Quit();
0

精彩评论

暂无评论...
验证码 换一张
取 消