本文介绍了如何将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);
推荐答案
//Clipboard.SetDataObject(obj);
//IDataObject IData = Clipboard.GetDataObject();
System.Drawing.Image image = Clipboard.GetImage();
这篇关于如何将MS Excel工作表格式化为图像并将其保存到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!