蒂達文翻譯翻譯社

//花式篇
mSheet.Range[起翻譯社迄].Merge;                                      //合併貯存格
mSheet.Cells.EntireColumn.AutoFit;                              //最適欄寬
mSheet.Cells.EntireRow.AutoFit;                                 //最適列高
mSheet.Columns[1].ColumnWidth := 100;                           //設定欄寬
mSheet.Rows[1].RowHeight := 100;                                //設定列高
mSheet.Rows[1].HorizontalAlignment := -4108;                    //程度置中(靠左:-4131;靠右:-4152)
mSheet.Rows[1].VerticalAlignment := -4108;                      //垂直置中(靠左:-4131;靠右:-4152)
mSheet.Rows[1].WrapText  := True;                               //主動換列
mSheet.Columns[1].Hidden := True;                               //埋沒

mSheet.Cells[1,1].Font.Size := 10;                              //設定字體巨細
mSheet.Cells[1,1].Font.Bold := True;                            //設定粗體字
......

//Excel篇
mExcel.DisplayAlerts := False;                                  //Disable 提醒訊息
mExcel.Visible := True;                                         //顯示 Excel 畫面
mExcel.ActiveWindow.FreezePanes := True;                        //凍結窗格(上一行一定要先選列或格)
mExcel.ActiveWindow.Zoom := 75;                                 //顯示比率為75%
mExcel.ActiveWindow.Zoom := True;                               //根據今朝選擇規模主動決議視窗巨細

//選取篇
mSheet.Cells.EntireColumn                                       //所有欄
mSheet.Cells.EntireRow                                          //所有列
mSheet.Cells                                                    //所有儲存格
mSheet.Columns[1]                                               //第一欄
mSheet.Rows[1]                                                  //第一列
mSheet.Cells[r翻譯社c]                                               //第r列第c欄
mSheet.Range[起翻譯社迄]                                             //區間選擇(起迄可以是欄、列、格)

//設定格局化前提
mSheet.Cells[1,1].FormatConditions.Delete;                      //斷根花樣化前提
mSheet.Cells[1,1].FormatConditions.Add[Type:='1', Operator:='1', Formula1:='1', Formula2:='2']; //新增格式化前提(最多3個)
//參數說明
//  參數   中文說明                                  申明
//======== ======== =======================================================================
//Type     濫觞型態 1.貯存格的值 2.公式
//Operator 法則     1.介於 2.不介於 3.等於 4.不等於 5.大於 6.小於 7.大於或等於 8.小於或等於
//Formula1 前提起
//Formula2 前提迄
mSheet.Cells[1,1].FormatConditions(1).Interior.ColorIndex := 3; //設定前提一為底色紅色
//可設定之格局有:Fonts(字型)、Borders(外框)、Interior(圖樣)

//填值篇
mSheet.Cells[1翻譯社1].Value:= '內容';                               //欄位填值
mSheet.Cells[1翻譯社1].Formula:= '公式';                             //欄位填入公式
mSheet.Cells[1翻譯社1].FormulaR1C1:= '公式';                         //欄位填入公式
mSheet.Cells[1翻譯社1].HasFormula                                    //儲存格是否有公式

mExcel.Selection.Subtotal(1,-4157,VarArrayOf([4,5,6,7,8]),True翻譯社False翻譯社True);  //做小計
//參數申明
//      參數               中文申明         預設值
//================ ======================== ======
//GroupBy          分組小計欄位             1
//Function         使用函數                 -4157 加總
//TotalList        新增小計位置
//Replace          取代目前小計             True
//PageBreaks       每組資料分頁             False
//SummaryBelowData 摘要資料置於小計資料下方 True
//可使用函數:-4157 加總;-4106 平均值;-4112 項目個數;-4113 數字項目數;-4136 最大值;-4139 最小值;

//列印篇
mSheet.PageSetup.PrintTitleRows := '$1:$1';                      //列印標題列
mSheet.PageSetup.CenterHeader := '表頭';                         //中頁首
mSheet.PageSetup.LeftHeader   := '頁次: &P / &N';                //左頁首
mSheet.PageSetup.RightHeader  := '';                             //右頁首
mSheet.PageSetup.CenterFooter := '& &P / &N';                   //中頁尾
mSheet.PageSetup.LeftFooter   := '頁次: &P / &N';                //左頁尾
mSheet.PageSetup.RightFooter  := '';                             //右頁尾
mSheet.PageSetup.PrintArea := '$B$1:$N$300';                     //設定列印規模
mSheet.PageSetup.Orientation := 2;                               //1.直印 2.橫印
mSheet.PageSetup.Zoom := 65;                                     //列印時小成65%
mSheet.PageSetup.Zoom := True;                                   //利用頁次縮放功能
mSheet.PageSetup.FitToPagesWide := 1;                            //縮放成一頁寬(需共同Zoom = True)
mSheet.PageSetup.FitToPagesTall := 1;                            //縮放成一頁高(需共同Zoom = True)
mSheet.PageSetup.PaperSize := 8;                                 //設定紙張巨細 8:A3、9:A4
mSheet.PageSetup.TopMargin := 1/0.035;                           //頂邊距1cm
mSheet.PageSetup.BottomMargin := 1/0.035;                        //底邊距1cm
mSheet.PageSetup.LeftMargin := 1/0.035;                          //左邊距2cm
mSheet.PageSetup.RightMargin := 1/0.035;                         //右側距2cm
mSheet.PageSetup.HeaderMargin := 1/0.035;                        //頁首1cm
mSheet.PageSetup.FooterMargin := 1/0.035;                        //頁尾1cm
mSheet.PageSetup.CenterHorizontally := True;                     //頁面程度居中
mSheet.PageSetup.CenterVertically := False;                      //頁面垂直居中

mSheet.Cells[1].Interior.ColorIndex := 38;                      //設定底色為玫瑰色
mSheet.Cells[1].Interior.ColorIndex := 6;                       //設定底色為黃色
mSheet.Cells[1].Interior.ColorIndex := 36;                      //設定底色為淺黃色
mSheet.Cells[1].Interior.ColorIndex := 35;                      //設定底色為淺綠色

//Workbook篇
mWorkBook := mExcel.WorkBooks[1];                               //將指定變數設定第一個活頁簿(數字可以用名稱代替)
mWorkBook.Name :='內容';                                        //調換WorkBook名稱
mExcel.WorkBooks.Add;                                           //新增一個空白活頁簿
mExcel.WorkBooks.Open(完全路徑);                                //開啟Excel檔
mExcel.WorkBooks[mFile].Close;                                  //關閉Excel檔
DeleteFile(mPath+mFile);                                        //刪除Excel檔
mWorkBook.SaveAs(mPath+mFile翻譯社-4143);                            //儲存Excel檔

//框線
mSheet.Cells[1,1].Borders[n].LineStyle := 1;
mSheet.Cells[1,1].Borders[n].Weight := 2;
//n = 5.左上右下斜線 6.左下右上斜線 7.左邊線 8.上邊線 9.下邊線 10.右側線 11.垂直線 12.水平線
//Borders可以使用參數:
// LineStyle = 1 實線;-4115 短虛線;4 長短虛線;5 長短短虛線;-4118 細虛線;-4119 雙實線
// Weight =  由細到粗:1 --> 2 --> -4138 --> 4
// ColorIndex = 色彩

  花了兩天的時間把這幾年用過的 Excel VBA 指令彙總起來,分門別類,方便今後使用,順手貼出來給有需要的朋友翻譯看倌多顧惜啊,這可是好幾年的心血說。(使用 Delphi 語法)


//刪除多餘Sheet
if (mWorkBook.Sheets.Count > 1) then
begin
  for i:=2 to mWorkBook.Sheets.Count do
    mWorkBook.Sheets[2].Delete;
end;

mSheet.Outline.ShowLevels(2);                                    //把小計層級設2顯示

//資料篇
mSheet.Cells.EntireColumn.AutoFilter;                           //主動挑選

mSheet.Columns[1].NumberFormatLocal := '@';                     //設定欄位格局[文字]
mSheet.Columns[1].NumberFormatLocal := '#,##0_ ';               //設定欄位格局[數值(整數位 三位一撇)]
mSheet.Columns[1].NumberFormatLocal := '#,##0_ ;[紅色]-#,##0 '; //設定欄位花式[數值(整數位 三位一撇 負數紅字)]
mSheet.Columns[1].NumberFormatLocal := '#,##0_);[紅色](#,##0)'; //設定欄位花樣[數值(整數位 三位一撇 負數括號紅字)]
mSheet.Columns[1].NumberFormatLocal := '0.00_ ';                //設定欄位花式[數值(小數兩位)]
mSheet.Columns[1].NumberFormatLocal := '0.0_);[紅色](0.0)';     //設定欄位格式[數值(小數一名 負數紅字)]
mSheet.Columns[1].NumberFormatLocal := '0.00%';                 //設定欄位格式[百分比(小數兩位)]

//Sheet篇
mSheet := mExcel.WorkBooks[1].WorkSheets[1];                    //將指定變數設定第一個工作表(數字可以用名稱庖代)
mSheet.Name :='內容';                                           //調換Sheet名稱
mSheet.Copy[After := mWorkBook.Sheets[mWorkBook.Sheets.Count]]; //將mSheet複製到mWorkBook最後
mSheet.Move[After := mWorkBook.Sheets[mWorkBook.Sheets.Count]]; //將mSheet搬移到mWorkBook最後
mWorkbook.Sheets.Add[After:=mWorkbook.Sheets[mSheetCount-1]];   //新增一個空白工作表
mWorkBook.Sheets[1].Delete;                                     //刪除指定Sheet
mWorkBook.Sheets[1].Activate;                                   //將指定Sheet設為使用中



以下內文出自: http://blog.xuite.net/luckysft/blog/14509469-%E5%B8%B8%E7%94%A8+Excel+VBA+%E6%8C%87%E4%BB%A4%E5%BD%9有關翻譯的問題歡迎諮詢天成翻譯公司

arrow
arrow
    文章標籤
    翻譯社
    全站熱搜

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