如何在新LINE上获取文字? [英] How to get the text on new LINE?

查看:62
本文介绍了如何在新LINE上获取文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将docx文件转换为文本文件,但问题是整个文本是逐行编写的。



例如Docx文件文本。

Hello.How RU?

罚款。



在转换后的文本文件中它也来自新线上的精细不继续吗? mark。

I converted docx file into text file but the problem is that the whole text are written in line by line.

e.g Docx file text.
Hello.How R U?
Fine Thanku.

in converted text file it also come from "Fine" on new line not in continue after ? mark.

推荐答案

我发送我的代码..

所以请给我一个解决方案如何在文本文件中写入文本后转换?





使用系统;

使用System.Configuration;

使用System.Data;

使用System.Linq;

使用System.Web;

使用System.Web.Security;

使用System.Web.UI;

使用System.Web.UI.HtmlControls;

使用System.Web.UI.WebControls;

使用System.Web.UI.WebControls.WebParts;

使用System.Xml.Linq;

使用System.IO;

使用Microsoft.Office.Interop.Word;

使用System.Text;





public partial class _Default :System.Web.UI.Page

{

protected void Page_Load(object sender,EventArgs e)

{}

protected void Button1_Click(object sender,EventArgs e)

{

File Upload1.SaveAs(Server.MapPath(FileUpload1.FileName));

object filename = Server.MapPath(FileUpload1.FileName);

Microsoft.Office.Interop.Word。 ApplicationClass AC = new Microsoft.Office.Interop.Word.ApplicationClass();

Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();

object readOnly = false;

object isVisible = true;

object missing = System.Reflection.Missing.Value;

尝试

{

doc = AC.Documents.Open(ref filename,ref missing,ref readOnly,ref missing,ref missing,ref missing,ref missing,

ref缺失,ref缺失,ref遗失,ref遗失,ref isVisible,ref missing,ref missing,ref missing,ref missing);



TextBox1.Text = doc.Content.Text;



// string txt = TextBox1.Text;

string st r =G:\\test.txt;

string [] lines = {TextBox1.Text};



使用(FileStream fs = new FileStream(str,FileMode.Create))

{

使用(StreamWriter sw = new StreamWriter(fs))

{

foreach(字符串行)

sw.Write(line + sw.NewLine);

}

}

}

catch(例外情况)

{}

}

}
I send my Code..
So please give me a solution How to write a text in text file on line after conversion?


using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using Microsoft.Office.Interop.Word;
using System.Text;


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
FileUpload1.SaveAs(Server.MapPath(FileUpload1.FileName));
object filename = Server.MapPath(FileUpload1.FileName);
Microsoft.Office.Interop.Word.ApplicationClass AC = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
try
{
doc = AC.Documents.Open(ref filename,ref missing,ref readOnly,ref missing,ref missing,ref missing,ref missing,
ref missing,ref missing,ref missing,ref missing,ref isVisible,ref missing,ref missing,ref missing,ref missing);

TextBox1.Text = doc.Content.Text;

//string txt = TextBox1.Text;
string str = "G:\\test.txt";
string[] lines = {TextBox1.Text};

using (FileStream fs = new FileStream(str, FileMode.Create))
{
using (StreamWriter sw = new StreamWriter(fs))
{
foreach (String line in lines)
sw.Write(line + sw.NewLine);
}
}
}
catch (Exception ex)
{}
}
}


这篇关于如何在新LINE上获取文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆