Public class CoverExcellToImage
{
Private static string SAVEEXCELJPG = @ "c:/temp/10902.16.jpg ";
Private static readonly string [] ArrRang = new string [] {"A", "B", "C", "D", "E", "F ", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P ", "Q", "R", "S", "T", "U", "V", "W", "X", "Y ", "Z "};
Public static event TECOSFIS. SFIS. UpdateImage. ShowMessage eventShowMessage;
Public static string StrRouseFile = "";
Public static List <string> ListFileName = new List <string> ();
Public static string GetExcel (string excelFilePath)
{
If (! System. IO. Directory. Exists ("c:/temp ")){
System. IO. Directory. CreateDirectory ("c:/temp ");
}
Microsoft. Office. Interop. Excel. Application app = new Microsoft. Office. Interop. Excel. Application ();
App. DisplayAlerts = false;
Object objMis = Type. Missing;
Microsoft. office. interop. excel. workbook singleExcel = app. workbooks. open (excelFilePath, objMis, objMis );
Try
{
StrRouseFile = excelFilePath;
// Wsheet. UsedRange. Select ();
If (eventShowMessage! = Null)
{
EventShowMessage (1, singleExcel. Worksheets. Count );
}
For (int I = 1; I <= singleExcel. Worksheets. Count; I ++)
{
Microsoft. Office. Interop. Excel. Worksheet wsheet = (Microsoft. Office. Interop. Excel. Worksheet) singleExcel. Worksheets [I];
ListFileName. Add (wsheet. Name );
Object ranobj = DBNull. Value;
// Set the selected cell and copy it out.
Int iRows = 36;
Int iCols = 8;
# Contents to be modified in warning
Wsheet. get_Range ("A5", ArrRang [iCols] + iRows. ToString (). Copy (ranobj );
IDataObject iData = Clipboard. GetDataObject ();
Bitmap bits = (Bitmap) iData. GetData (DataFormats. Bitmap );
Bitmap myBitmap = new Bitmap (bits. Width, bits. Height );
Graphics g = Graphics. FromImage (myBitmap );
G. DrawImage (bits, 0, 0 );
MyBitmap. Save (string. Format (SAVEEXCELJPG, wsheet. Name ));
Clipboard. SetDataObject ("");
MyBitmap. Dispose ();
Bits. Dispose ();
If (wsheet! = Null)
{
System. Runtime. InteropServices. Marshal. ReleaseComObject (wsheet );
Wsheet = null;
}
If (eventShowMessage! = Null)
{
EventShowMessage (2, I );
}
}
}
Catch (Exception Excel)
{
Throw Excel;
}
Finally
{
# Region releases resources www.2cto.com
SingleExcel. Close (null, null, null );
App. Workbooks. Close ();
App. Quit ();
If (singleExcel! = Null)
{
System. Runtime. InteropServices. Marshal. ReleaseComObject (singleExcel );
SingleExcel = null;
}
If (app! = Null)
{
System. Runtime. InteropServices. Marshal. ReleaseComObject (app );
App = null;
}
GC. Collect ();
# Endregion
}
Return string. Empty;
}
}
Principle:
Copy each sheet in the excell file to the clipboard, and then save the data in the clipboard as a chip.
From unlimited imagination