close

 

object missing = System.Reflection.Missing.Value;

 

ApplicationClass app = new ApplicationClass();

    

Workbook workbook = app.Workbooks.Open(MyPath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);

 

Worksheet sheet = (Worksheet)workbook.Worksheets.get_Item(1);

 

app.Cells[1, 1] = "哈哈";

 

app.Cells.Font.Size = 10;

 

//Range range = sheet.get_Range("A1", "C4");

 

//object[,] value;

 

//value = (object[,])range.get_Value(missing);

 

//int rows = value.GetUpperBound(0);

 

//int cols = value.GetUpperBound(1);

 

//sheet.SaveAs(MyPath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, myExcel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing);

 

 workbook.Save();

 

 

 

 

 

 

 

 

app.Quit();      

        

System.Runtime.InteropServices.Marshal.ReleaseComObject(app);


workbook = null;


sheet = null;


range = null;


app = null;


GC.Collect();

 

 

 

 

另外一些:

 

 
sheet.Cells.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignTop; //
垂直
sheet.Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;//水平
sheet.Cells.EntireRow.AutoFit(); //
自動調整列高
sheet.Cells.EntireColumn.AutoFit(); //
自動調整欄寬  
sheet.get_Range("A:A", Type.Missing).Font.Color = 255;

sheet.get_Range("A:A", Type.Missing).NumberFormatLocal = "@"; //儲存格格式都設為文字

 

 


 

  

app.Visible = true;//讓Excel文件可看見

mapp.DisplayAlerts = false;//停用警告訊息

sheet.Name = "Welkingunther"; 
workbook.Close(false, Type.Missing, Type.Missing);

arrow
arrow
    全站熱搜

    welkingunther 發表在 痞客邦 留言(0) 人氣()