如何在ASP.NET中为Excel工作簿命名 [英] How to give name to excel Workbook in ASP.NET

查看:199
本文介绍了如何在ASP.NET中为Excel工作簿命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我试图将图像导出到excel,我在那方面取得了成功.我真正需要的是当我单击导出"以使其表现出色时,是否要保存Excel的"Book1"?

但是我想将默认名称从"Book1"更改为其他名称.我曾经被

Myworkbook.name ="Test";

在这里我得到一个错误.您能告诉我如何在ASP.Net中为工作簿设置名称吗?


在此先感谢

Sandeep Paruchuru

Dear all,

I am trying to export an image to excel i was succeed in that. What i am actually need is when i click on Export to excel its showing do you want to save the excel ''Book1''?

But i want to change the Default name as ''Book1'' to some other name. I was used

Myworkbook.name="Test";

Here i am getting an error. Can u people please tell me how to set name to workbook in ASP.Net


Thanks in Advance

Sandeep Paruchuru

推荐答案

此处是InterOp代码,用于将特定工作簿重命名为:
Here is InterOp code to rename the specific work book as:
using Excel = Microsoft.Office.Interop.Excel; 

    object oMissing = System.Reflection.Missing.Value;
    Excel.ApplicationClass xl=new Excel.ApplicationClass();
        Excel.Workbook xlBook;
        Excel.Worksheet xlSheet;
        string laPath = Server.MapPath(@"\excel\xl_table.xls");
        xlBook = (Workbook)xl.Workbooks.Open(laPath,oMissing,
          oMissing,oMissing,oMissing ,oMissing,oMissing,oMissing
         ,oMissing,oMissing,oMissing,oMissing,oMissi ng,oMissing,oMissing);
        xlSheet = (Worksheet)xlBook.Worksheets.get_Item(1);
        xlSheet.Name = "MyOwnSheet";
        xlBook.Save();
        xl.Application.Workbooks.Close();


这篇关于如何在ASP.NET中为Excel工作簿命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆