【问题标题】:c# How can i detect end of page in a Word document with Word Interopc#如何使用Word Interop检测Word文档中的页尾
【发布时间】:2019-04-08 10:48:06
【问题描述】:

我正在使用 c# Interop Word 进行开发,我需要知道页面何时结束,因为我正在创建一个 Word 表。行数并不总是相同的,如果页面没有结束,那么我必须插入一个断页。

我该怎么做?

【问题讨论】:

  • 你能定义什么是页面吗?有段落和特殊换行符,但填充页面的流程也将由字体大小和页面大小值决定..
  • 如何获取页面大小值?我认为这是我的问题。
  • 页面大小是一个文档属性,但它是物理单位,而不是行。如果你的线条有一个固定的高度,事情会变得容易得多。
  • 我有一个固定的高度:float cent = (float)0.42; var cmimeters = wordApp.Application.CentimetersToPoints(cent);现在,我怎么知道最大行数?
  • 您必须与打印机驱动程序讨论页面大小。但是,由于您还有表格和图像,这可能会变得更加复杂..

标签: c# ms-word interop


【解决方案1】:

如果您使用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();

【讨论】:

  • 这和页面有什么关系??
  • @lok​​-ridgmont 谢谢你的回答,但我在这个 Word 文件中写作,有表格、图像、段落......我只想知道我什么时候到达页面。
猜你喜欢
  • 2011-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-31
相关资源
最近更新 更多