C 操縱Excel常用語句

2021-04-17 19:10:18 字數 1414 閱讀 8258

c#操縱excel常用語句(1)插入一定數量的行數

((excel._worksheet)excel.sheets [1]).get_range (excel.cells [1,1],excel.cells[4,1]).entirerow .insert (missing,missing);

(2)輸出報表,如果report1存在,則把模板存為report2.xls

for(int k=1;;k++) }

(3)把template目錄下的模板拷貝到export目錄下,路徑和檔名為上述(2)裡面的temppath2:

mode.copyto(temppath2,true);

(4)開啟這個從模板拷貝到export目錄的檔案,並在第i行、j列插入內容:

object missing=missing.value;

在第i行、j列寫入內容:

xst=(excel.worksheet)myexcel.sheets [1];

xst.cells [i,j]=textbox1.text ;  //等於號後面可以是任何相容的物件

(5)將第1行到40行的行高設為14.25:

xst.get_range (xst.cells [1,1],xst.cells [40,1]).rowheight =14.25;

(6)設定邊框

xst.get_range(excel.cells[4,2],excel.cells[rowsum,colindex]).borders.linestyle = 1;

(8)增加sheet並命名sheet

private void button1_click(object sender, system.eventargs e)

for(int i=1;i<=6;i++) }

(9)插入(例如插入d盤根目錄下的tt.bmp,必須新增引用:microsoft.office object library物件庫,並在窗體最前面有using office = microsoft.office.core;)

xst.shapes .addpicture ("d://tt.bmp",microsoft.office .core .msotristate.msofalse ,microsoft.office .core .msotristate.msotrue ,10,10,150,150);

--通用方法:

還有很多c#操作excel的方法,不在此舉例了。

當你不知道怎麼寫c#**操作excel時,乙個比較通用的方法是:

在excel裡->工具->巨集->錄製新巨集,然後你將你想要的效果操作一遍,然後單擊工具->巨集->停止錄製,然後單擊工具->巨集->巨集->編輯,就可以檢視**了,這些**與c#裡面的**大部分是類似的,有些**的引用不一定完全一樣,但你最起碼知道了這個引用方法是從哪個父物件引用的,在vs裡面找起來也方便很多。

mysql常用語句 MySQL常用語句

create table student id int primary key auto increment comment 學號 name varchar 200 comment 姓名 age int comment 年齡 comment 學生資訊 修改表注釋 alter table studen...

php mysql 常用語句 mysql常用語句

一 修改mysql使用者密碼 mysql h localhost u root p 命令列登入 update user set password password 123456 where user root 二 資料庫操作 show databases 顯示資料庫 create database ...

C 常用語句簡介

目錄 在c 當中所有的變數都需要宣告,如 int wordcnt 我們宣告了乙個int型別的變數wordcnt,這樣的語句會告訴編譯器兩個關鍵資訊。乙個是變數所需要的記憶體,乙個是這塊記憶體的名稱。比如在這個例子當中,我們宣告了乙個int型的變數。它佔據32個二進位制位,也就是4個位元組,這塊記憶體...