如何将MS Excel工作表格式化为图像并将其保存到服务器 [英] How can I format an MS Excel sheet to an image and save it to server

查看:133
本文介绍了如何将MS Excel工作表格式化为图像并将其保存到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想由客户端开发一个程序,上传excel,并将excel表转换为图片,保存到服务器,我使用剪贴板,将图片复制到其中,但是复制成功,但是无法进入图片.

I want to develop a program by the client, upload excel, and conmvert excel sheet into a picture, save to the server, I use the clipboard, copy the picture in, but the copy is successful, but can not get into the picture .

Excel.Application m_objExcel = null;
            Excel.Workbook m_objBook = null;
            Excel.Workbooks m_objBooks;
            Excel._Worksheet sheet;
            Excel.Range m_Range;
            System.DateTime StartTime = System.DateTime.Now;
            string filename = @"D:\test.xls";
            m_objExcel = new Excel.Application();
            m_objExcel.UserControl = false;
            m_objExcel.DisplayAlerts = false;
            m_objExcel.Visible = false;
            m_objExcel.Workbooks.Open(filename, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
             Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
            m_objBook = m_objExcel.ActiveWorkbook;
            sheet = (Excel.Worksheet)m_objBook.ActiveSheet;
           
            //Weeks
            //获取图表对象
            //ChartObject chartObj = (ChartObject)sheet.ChartObjects(1);
            //Chart xlChart = chartObj.Chart;
            //GdiplusStartupInput

            //设置数据源
            Range chartRange = sheet.get_Range("A1", "G14");
            //Clipboard
            Clipboard.Clear();
            Object obj = chartRange.CopyPicture(XlPictureAppearance.xlScreen, XlCopyPictureFormat.xlBitmap);
            //Clipboard.SetDataObject(obj);
            //IDataObject IData = Clipboard.GetDataObject();
            System.Drawing.Image image = Clipboard.GetImage();
            image.Save("D:\\test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);


推荐答案

Excel是一个桌面应用程序-像这样使用它通常不是一个好主意,因为IIS作为Windows服务运行-您通常不这样做"无法访问 Windows工作站 [ EPPLUS [ ^ ]以访问电子表格中的数据.

您可以使用 iTextSharp [ XtraReports [ ^ ]代替图像提示.显然,如果您确实想要:),可以使用gdi +(System.Drawing)将信息渲染到图像上.
问候
Espen Harlinn
Excel is a desktop application - using it like this is usually not a bright idea since IIS runs as a windows service - you usually don''t have access to the windows station[^].

Use something like EPPLUS[^] to access data from the spreadsheet.

You can use iTextSharp[^] to create a pdf, or a reporting tool like XtraReports[^] as a replacement for the image idea. Obviously you can use gdi+ (System.Drawing) to render the information to an image if you really want to :)

Regards
Espen Harlinn


Clipboard.GetImage();
在此处为空
Clipboard.GetImage();
Null at here


Clipboard.GetImage();具有空值,因为您在剪贴板设置对象的位置注释了上面的行.请参见下文

Clipboard.GetImage(); has null value because you commented the above line from where Clipboard set the object .. see below

//Clipboard.SetDataObject(obj);
//IDataObject IData = Clipboard.GetDataObject();
System.Drawing.Image image = Clipboard.GetImage();


这篇关于如何将MS Excel工作表格式化为图像并将其保存到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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