Word文档的C#中的新行

时间:2013-10-03 05:21:57

标签: c#

如何在上传word文档时识别新行c#..我必须在word文档中给下一行作为一个新单词,这里发生了什么意味着如果我在.doc中添加三个或更多单词在单独的行中它作为一个单词我想要分隔单词但是如果我在一个单词之后给出一个空格如果我在新行中开始一个新单词,那么它就像预期的那样没有给出空间

钱 功率 现金

moneypowercash

像这样,如果我在这些词之后给予空间,它会如预期的那样得到这里 如何在这里解决这个问题我会给我的代码生成这个关键字

protected void btnSubmit_Click(object sender, EventArgs e)
{
 try
 {

   if (cmbDepartment.SelectedValue != "0" && cmbDocumentType.SelectedValue != "0")
     {

      TodayDate = DateTime.Today.ToString("yyyy-MM-dd");
      TempFolder = System.Configuration.ConfigurationManager.AppSettings["TempWorkFolder"];
      TextReader reader = new FilterReader(TempFolder + Session["EncyptImgName"]);
      StringBuilder Keywords = new StringBuilder();
      using (reader)
      {
         Keywords = Keywords.Append(reader.ReadToEnd());
      }
      //remove common words
      string[] removablewords = { ":", ".", "~"};
      foreach (string st in removablewords)
      {
           Keywords.Replace(st, " ");
      }    

      //Reomve unwated spaces
      while (Keywords.ToString().Contains("  "))
      {
          Keywords.Replace("  ", " ");
      }
      string str = Keywords.ToString();
      Keywords.Clear();
      Keywords.Append("<words><s>" + str.Replace(" ", "</s><s>") + "</s></words>");
      string xml = Keywords.ToString();
      XElement items = XElement.Parse(xml);
      var groups = from t in items.Descendants("s")
                   group t by t.Value.ToLower() into g
                   select new KeyFrequency(g.Key, g.Count());
      groups = groups.OrderByDescending(g => g.Frequency).Take(15);

      keyvalues = new List<string>();
      foreach (KeyFrequency g in groups)
      {
          keyvalues.Add(g.Key);
      }

      for (key = 0; key < keyvalues.Count && key < 10; key++)
       {
       Button btn = (Button)pnlKeywords.FindControl("Button" + Convert.ToString(key + 1));
                    btn.Visible = true;
                    btn.Text = keyvalues[key];
                    btn.CommandArgument = keyvalues[key];
                }
                if (key < 10)
                {
                    for (key = key; key < 10; key++)
                    {
                        Button btn = (Button)pnlKeywords.FindControl("Button" + Convert.ToString(key + 1));
                        btn.Visible = false;
                    }
                }
                else
                {
                    AsyncFileUpload1.BackColor = System.Drawing.Color.Red;
                }
            }
        }
        catch (Exception ex)
        {
            Button1.Text = "Keywords Not Available for This Document";
            Button1.CommandArgument = null;
            Button2.Visible = false;
            Button3.Visible = false;
            Button4.Visible = false;
            Button5.Visible = false;
            Button6.Visible = false;
            Button7.Visible = false;
            Button8.Visible = false;
            Button9.Visible = false;
            Button10.Visible = false;

        }

    }

1 个答案:

答案 0 :(得分:0)

对于每个新行,请尝试将\n替换为"</w:t><w:br/><w:t>"。它对我有用。

string.Replace("\n", "</w:t><w:br/><w:t>")