簡體   English   中英

c#如何使用Word Interop在Word文檔中檢測頁面結尾

[英]c# How can i detect end of page in a Word document with Word Interop

我正在使用c#Interop Word進行開發,並且我需要知道頁面何時結束,因為我正在創建Word Table。 行數並不總是相同的,如果頁面沒有結束,那么我必須插入一個中斷頁面。

我怎樣才能做到這一點 ?

如果您使用Streamreader讀取Word文件,則可以執行以下操作:

string path = @"C:\..."; // the path of your word file
Streamreader sr = new Streamreader(path);
while (!sr.EndOfStream) {
    // what you want to do
{
sr.Close();

如果您想知道文件的結束行,只需創建一個count數值,然后在文件結束時檢查count就可以了:

string path = @"C:\..."; // the path of your word file
int count = 0;
Streamreader sr = new Streamreader(path);
while (!sr.EndOfStream) {
    // what you want to do
    count++;
{
sr.Close();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM