USING OFFICE; Using System.Diagnostics;
Namespace Ysj.publicClass {/// /// Sexcel's summary description. /// summary> public class SExcel {Excel.Application Ex = null; Excel.Workbook ExBook = null; object oMissing = System.Reflection.Missing.Value; SqlDataReader Dr; TSqlDB Db = new TSqlDB (); DateTime dtapp1; DateTime DTAPP2;
Public sexcel () {// // Todo: Add constructor logic //} here
public void OpenFile (string strFileName) {dtapp1 = DateTime.Now; Ex = new Excel.ApplicationClass (); dtapp2 = DateTime.Now; ExBook = Ex.Application.Workbooks.Open (strFileName, oMissing, oMissing, oMissing, oMissing, oMissing , OMISsing, Omissing, Omissing, Omissing, Omissing, Omiissing, OMISING; EX.DISPLAYALERTS = FALSE;}
/// /// Set cell attribute /// summary> /// line param> /// column < / param> /// param> public void setcells (int Row, int column, string string {ex.cells [rot, column] = str;} // / /// Setting cell grid font /// summary> /// font size param> public void setfont (int fontsize) {ex.cells.font. SIZE = fontsize;}
/// /// kills Excel process /// summary> public void killprocess () {foreach (Process P IN Process.getProcessesbyName ("Excel")) {if (p.StartTime> = DTAPP1 && P. StartTime <= DTAPP2) {p.kill ();}}}
public void Save (string strSavePath) {Ex.Application.ActiveWorkbook.SaveAs (strSavePath, oMissing, oMissing, oMissing, oMissing, oMissing, Excel.XlSaveAsAccessMode.xlNoChange, oMissing, oMissing, oMissing, oMissing); ExBook.Application.ActiveWorkbook.Close (false, omissing, false); //exbook.close (omissing ,omissing ,omissing; eXbook = null; ex.application.quit (); ex.quit (); ex= null; //gc.collect () KillProcess ();} /// /// Insert picture /// / summary> /// picture path param> /// Left long param> /// param> /// picture width param> /// Picture of high param> Public void insertphoto (string photopath, float left, float top, float width, float height) {if (System.IO.File.exists (photo)) {excel.worksheet xsheet = Excel.Worksheet; //xsheet.shapes.addpicture(Photopath, Msotristate.msofalse, Msotristate.msotrue, 165, 190, 75, 30); xsheet.shapes.addpicture (Photopath, M Sotristate.msofalse, Msotristate.msotrue, Left, Top, Width, Height;}}
/// /// Established new workbook /// summary> /// workbook name param> public void addsheet (String Sheetname) {Excel.Worksheet XST XST = (Excel.worksheet) exbook.sheets.add (Type.Missing, Type.missing, Type.Missing, Type.Missing); xst.name = sheetname;}}}