C 取得MS Word的總頁數

2022-02-17 00:42:53 字數 1076 閱讀 2503

用c#來操作word最方像便的方法是引入word的api類庫:

using

microsoft.office.interop.word;

引入後就可以對word進行操作了:

code

//啟動word程式

=new

object

omissing 

=system.reflection.missing.value;

object

filepath =""

; //

這裡是word檔案的路徑

//開啟檔案

document myworddoc 

=ref

filepath, 

refomissing, 

refomissing, 

refomissing,

refomissing, 

refomissing, 

refomissing, 

refomissing,

refomissing, 

refomissing, 

refomissing, 

refomissing,

refomissing, 

refomissing, 

refomissing, 

refomissing);

//下面是取得開啟檔案的頁數

intpages 

=myworddoc.computestatistics(wdstatistic.wdstatisticpages, 

refnothing);

//關閉檔案

myworddoc.close(

refomissing, 

refomissing, 

refomissing);

//退出word程式

refnothing, 

refnothing, 

refnothing);

關於word的操作還有很多, 今天我做專案時為了取得總頁數, 在網上找了很久都找不到, 後來自己慢慢試出來了.

留下個記號方便以後用, 也方便其他需要的朋友.

分頁的總頁數演算法

總記錄數 totalrecord 每頁最大記錄數 pagesize 演算法一 獲取總頁數 總條數 每頁最大記錄數 public static int gettotalpage int totalrecord,int pagesize view code 獲取總頁數 總條數 每頁最大記錄數 publi...

分頁計算總頁數的演算法

展示列表,使用分頁的時候,經常會遇到分頁的使用,比如使用mybatis通過sql語句分頁實現分頁功能。本次主要是寫對返回的資料進行分頁的總頁數計算,故分頁不進行贅述,只簡要說明一下對得到的結果計算分頁的總頁數 有兩種實現方式 方法1 totalpage total pagesize 0 total ...

關於分頁中總頁數以及起止條數的計算公式

很多情況下我們需要用到手動分頁,這樣可以減少查詢的sql壓力,也方便展示資料。對於手動分頁來說,一般需要前端向我們傳遞兩個引數 currpage 當前頁 pagesize 每頁展示的條數 下面我們來寫三個公式,分別對起始條數firstindex 截止條數lastindex 總頁碼數countpage...