.NET operation Excel

xiaoxiao2021-03-06  40

USING OFFICE; Using System.Diagnostics;

Namespace Ysj.publicClass {///

/// Sexcel's summary description. /// 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 /// /// line /// column < / param> /// public void setcells (int Row, int column, string string {ex.cells [rot, column] = str;} // / /// Setting cell grid font /// /// font size public void setfont (int fontsize) {ex.cells.font. SIZE = fontsize;}

///

/// kills Excel process /// 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 /// /// picture path /// Left long /// /// picture width /// Picture of high 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 /// /// workbook name 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;}}}

转载请注明原文地址:https://www.9cbs.com/read-61440.html

New Post(0)