将文件作为字符串读取时,文件数据似乎已损坏
file data seems to be corrupted when reading file as a string
我正在尝试将文件读取为字符串。但是好像数据已经损坏了。
string filepaths = Files[0].FullName;
System.IO.StreamReader myFile = new System.IO.StreamReader(filepaths);
string datas = myFile.ReadToEnd();
但在数据中,它包含 "pk0101" 等而不是原始数据。我这样做是为了用这个字符串 data,datas 替换占位符。最后当我替换时,将替换文本替换为 0101 等。是因为数据中的内容吗?如何将文件读取为字符串。对你的帮助表示感谢。谢谢。
*.docx
是一种文件格式,在原始视图中表示 xml 文档。看一下 here 以更加熟悉此格式定义。
对于办公格式,Microsoft 建议使用 DocumentFormat.OpenXml
库中的 Open Xml SDK
。
Here 是一篇学习如何使用 Word 文件的好文章。
它的工作原理如下:
using (var wordDocument = WordprocessingDocument.Open(string.Empty, false))
{
var body = wordDocument.MainDocumentPart.Document.Body;
var text = body.GetFirstChild<Paragraph>().InnerText;
}
另外,看看这个 SO 问题:How do I read data from a word with format using the OpenXML Format SDK with c#?
我正在尝试将文件读取为字符串。但是好像数据已经损坏了。
string filepaths = Files[0].FullName;
System.IO.StreamReader myFile = new System.IO.StreamReader(filepaths);
string datas = myFile.ReadToEnd();
但在数据中,它包含 "pk0101" 等而不是原始数据。我这样做是为了用这个字符串 data,datas 替换占位符。最后当我替换时,将替换文本替换为 0101 等。是因为数据中的内容吗?如何将文件读取为字符串。对你的帮助表示感谢。谢谢。
*.docx
是一种文件格式,在原始视图中表示 xml 文档。看一下 here 以更加熟悉此格式定义。
对于办公格式,Microsoft 建议使用 DocumentFormat.OpenXml
库中的 Open Xml SDK
。
Here 是一篇学习如何使用 Word 文件的好文章。 它的工作原理如下:
using (var wordDocument = WordprocessingDocument.Open(string.Empty, false))
{
var body = wordDocument.MainDocumentPart.Document.Body;
var text = body.GetFirstChild<Paragraph>().InnerText;
}
另外,看看这个 SO 问题:How do I read data from a word with format using the OpenXML Format SDK with c#?