显示Excel工作簿而不保存在C#中 [英] Show Excel workbook without save in C#

查看:114
本文介绍了显示Excel工作簿而不保存在C#中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行时在WinForm应用程序(VS2008)中创建Excel文件.我正在从datagridview导出一些数据.导出后,我想在excel中显示此文件,但不想保存在任何地方.我的目标是将其用作在Crystal中创建报告的替代方法.

I am creating an Excel file in an WinForm app (VS2008) in runtime. I am exporting some data into it from datagridview. After export, i would like to show this file in excel, but dont want to save anywhere. My goal is to use it as an alternative of creating report in crystal. Is it possible ?

推荐答案

//Create excel object and load it.
 m_objExcel1 = new Excel.Application();
  m_objBook1 = (Excel.Workbook)m_objExcel1.Workbooks.Open(@"\FM-temp.xls", m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt);
                    m_objSheets1 = (Excel.Sheets)m_objBook1.Worksheets;
                    m_objSheet1 = (Excel._Worksheet)(m_objSheets1.get_Item(1));

                  //If you add following line to the excel object it will view in the explorer.

                    m_objBook1.Application.Visible = true;
        
                  //then simply add values to the fields. You can view it while adding the values.

  Excel.Range oRangeI = (Excel.Range)m_objSheet1.get_Range("B" + i.ToString(), m_objOpt);
                        oRangeI.Value2 = f.Name;


这篇关于显示Excel工作簿而不保存在C#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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