2015-04-23 30 views
0

如何获取word文档中的当前行作为整数?这甚至有可能吗?Word将当前行作为整数

public void Export(string filename, string name, string value, DataGridView dg, int iRows) 
    { 
     oWord = null; 
     object missing = System.Reflection.Missing.Value; 

     object lineNo = missing; 

     // Get word instance. 
     ExportData.GetWordInstance(ref oWord); 

     if (oWord != null) 
     { 
      try 
      { 
       int iPos = 1; 

       oDocs = oWord.Documents; 
       // Open document. 
       object fileName = DirectoryFiles.OpenFile(filename); 
       object readOnly = false; 
       object isVisible = true; 
       object oMissing = Type.Missing; 
       oDoc = oDocs.Open(ref fileName, ref oMissing, false, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, 
        ref oMissing, ref oMissing, ref oMissing); 

       oBookmarks = oDoc.Bookmarks; 

       if (name == "bookmarkPositions") 
       { 
        int rows = dg.Rows.Count * 3; 
        object oEndOfDoc = "bookmarkPositions"); 
        Word.Table oTable; 
        Word.Range wrdRng = oDoc.Bookmarks.Item(ref oEndOfDoc).Range; 
        oTable = oDoc.Tables.Add(wrdRng, rows + 1, 5, ref oMissing, ref oMissing); 
        // .... 

这就是我试图解决我的出口...

感谢您的帮助!

+1

什么构成“当前行”? - 需要更多细节。 –

+0

光标的行 – Jocelyn

+0

例如,如果我在第50行,则需要分页符。 – Jocelyn

回答

0

我自己解决的第一个问题。 要让每一页我插入下面的表头:

 oTable.Cell(1, 1).Row.HeadingFormat = -1; 

现在的主要问题:

for (int r = 0; r < dg.Rows.Count; r++) 
     { 
      oTable.Cell(j, 5).Range.Text = datagridview1["price", r].Value.ToString(); 
      .... 
     } 

在每一行中我有一个总和。 在每一页的末尾分别在表格的最后一页我想插入一个新的行与当前总和。

我该怎么做?