[英]converting docx,doc to open xml using open xml sdk 2.0 its working fine with docx when converting doc its error that file has corrupted data
[英]file contains corrupted data while converting docx to html c#
我正在從 SQL 數據庫 varbinary 字段值編寫 docx 文件。 文件寫入正確。 當我打開文件時,我收到消息“word fund unreadable content..”(下面的屏幕截圖)。 如果我單擊是,那么我將獲得包含正確內容的 docx 文件。 這里有 2 個任務,首先讀取數據庫並寫入 docx 文件,然后讀取 docx 文件並轉換為 html。
我需要將此 docx 文件轉換為 html,然后需要保存在數據庫中。 轉換時出現錯誤“文件包含損壞的數據” ,請參閱我下面的代碼以編寫 docx 並轉換為 html。
編寫docx代碼:
cmd.CommandText = "SELECT [pricing_discussion_ole] FROM [dbo].[Query] where deal_identifier='ARCGL00202020'";
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
int size = 1024 * 1024;
byte[] buffer = new byte[size];
int readBytes = 0;
int index = 0;
using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
while ((readBytes = (int)dr.GetBytes(0, index, buffer, 0, size)) > 0)
{
fs.Write(buffer, 0, readBytes);
index += readBytes;
}
}
}
}
將 docx 轉換為 HTml 但打開文件時出錯(文件包含損壞的數據)。 請問有什么幫助嗎?
寫入 docx 文件后,讀取 docx 並轉換為 html
using (WordprocessingDocument doc = WordprocessingDocument.Open(fileName, false)) // getitng error here (file contain corrupted data)
{
HtmlConverterSettings settings = new HtmlConverterSettings()
{
PageTitle = "My Page Title"
};
XElement html = HtmlConverter.ConvertToHtml(doc, settings);
var result = html.ToStringNewLineOnAttributes();
}
我遇到了這個問題,在編寫文件時從數據庫中獲取不需要的字節碼導致打開文件錯誤。 謝謝 !
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.