读取存储为blob的word doc文件,并将其内容转换为字符串

时间:2015-02-19 16:01:17

标签: c# mysql interop blob console-application

我在Mysql上有一个存储的word文档作为BLOB,我正在尝试使用c#读取它,获取其中的文本。有人可以给我一些关于如何做到这一点的简短代码。到目前为止,我已设法使用以下方法从数据库中读取字节:

using (MySqlConnection conn = new MySqlConnection())
{
    conn.ConnectionString = "connection string is here";
    conn.Open();
    MySqlCommand command = new MySqlCommand("select filename, document_content from job_db.person_documents where doc_type = 'application/msword' limit 1;", conn);
    using (MySqlDataReader reader = command.ExecuteReader())
    {
        // while there is another record present
        while (reader.Read())
        {
            Byte[] bytData = (byte[])reader[1];        
        }
    }
    conn.Close();
}

1 个答案:

答案 0 :(得分:0)

有一篇关于从内存中读取开放XML文档的办公室谈话文章。

https://msdn.microsoft.com/en-us/library/ee945362%28v=office.11%29.aspx

要访问这些方法,您需要Open XML SDK。

http://www.microsoft.com/en-au/download/details.aspx?id=30425

希望这足以让你开始。