Click here to Skip to main content
15,868,099 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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);

Thanks in advance!
Posted
Updated 25-Feb-11 1:42am
v5
Comments
Manfred Rudolf Bihy 25-Feb-11 7:32am    
Edited for conciseness, spelling and niceness.
Thomas Krojer 25-Feb-11 7:34am    
Nevertheless I don´t understand the question!

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
 
Share this answer
 
Clipboard.GetImage();
Null at here
 
Share this answer
 
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();
 
Share this answer
 
Comments
cherho0ny 25-Feb-11 7:55am    
chartRange.CopyPicture(XlPictureAppearance.xlScreen, XlCopyPictureFormat.xlBitmap);
copy the image into the Clipboard,when i use the application in c/s program ,it's can save the image ,but in b/s ,i can't get the image
i hope tomorrow i'll get The correct answer , i'm chinese ,will go to bed
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900