使用存储在SQL数据库中的图像检索rtf文本 [英] Retrieve rtf text with images stored in SQL database

查看:67
本文介绍了使用存储在SQL数据库中的图像检索rtf文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

**使用windows格式存储在sql数据库中的图像检索rtf文本,格式为格式和图像。



我尝试过的方法:



代码以windows形式存储



Dim cmd作为New SqlCommand(UPDATE questions SET ques_rich = @ques_rich WHERE quest_no = 1,con)



con.Open()



cmd.Parameters.AddWithValue(@ ques_rich,RichTextBox1.Rtf)



cmd.ExecuteNonQuery()



con.Close()

在asp.net中检索的代码



受保护的子Button1_Click(发送者)作为Object,e As EventArgs)处理Button1.Click

Dim con As New SqlConnection(Data Source = AHMEDHASHEM\SQLEXPRESS; Initial Catalog = test; Integrated Security = True)

Dim cmd1 As New SqlClient.SqlCommand

Dim tbl As New DataTable

Dim reader As SqlClient.SqlDataReader
Dim sql As String

sql =select * from question where quest_no = 1

cmd1 =新的SqlClient.SqlCommand(sql,con)

Dim ds1 As New DataSet()

Dim Adpt1 As New SqlDataAdapter(sql,con)

Adpt1.Fill(ds1,questions )

'rc = ds1.Tables(0).Rows.Count



con.Open()



tbxTinymce.Text = ds1.Tables(questions)。行(0)(ques_rich)

con.Close()

结束Sub

注意:我使用tinymce和freetextbox controle



也使用带有此代码的word文档



Dim wordApp As New Microsoft.Office.Interop.Word.ApplicationClass()



Dim nullobj As Object = System.Reflection.Missing .Value



Dim doc As Word.Document = wordApp.Documents.Open(c:\ freeinstall.doc)



Dim doc1 As Word.Document = wordApp.ActiveDocument



Dim m_Content As String = doc1.Content.Text



FreeTextBox1.Text = m_Content



doc.Close(nullobj,nullobj,nullobj)

该代码只检索文本而没有图像和格式

**retrieve rtf text with images stored in sql database with windows form in asp.net web form with exactly " format and images " **

What I have tried:

code to stor in windows form

Dim cmd As New SqlCommand("UPDATE questions SET ques_rich = @ques_rich WHERE quest_no = 1 ", con)

con.Open()

cmd.Parameters.AddWithValue("@ques_rich", RichTextBox1.Rtf)

cmd.ExecuteNonQuery()

con.Close()
code to retrieve in asp.net

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim con As New SqlConnection("Data Source=AHMEDHASHEM\SQLEXPRESS;Initial Catalog=test;Integrated Security=True")
Dim cmd1 As New SqlClient.SqlCommand
Dim tbl As New DataTable
Dim reader As SqlClient.SqlDataReader
Dim sql As String
sql = "select * from questions where quest_no = 1"
cmd1 = New SqlClient.SqlCommand(sql, con)
Dim ds1 As New DataSet()
Dim Adpt1 As New SqlDataAdapter(sql, con)
Adpt1.Fill(ds1, "questions")
'rc = ds1.Tables(0).Rows.Count

con.Open()

tbxTinymce.Text = ds1.Tables("questions").Rows(0)("ques_rich")
con.Close()
End Sub
note : i use tinymce and freetextbox controle

also use word document with this code

Dim wordApp As New Microsoft.Office.Interop.Word.ApplicationClass()

Dim nullobj As Object = System.Reflection.Missing.Value

Dim doc As Word.Document = wordApp.Documents.Open("c:\goinstall.doc")

Dim doc1 As Word.Document = wordApp.ActiveDocument

Dim m_Content As String = doc1.Content.Text

FreeTextBox1.Text = m_Content

doc.Close(nullobj, nullobj, nullobj)
that code retrieve text only without images and formatting

推荐答案

是的,这不是那么简单。你不会在HTML中完美地再现RTF文档。 RFT不是HTML。 HTML的行为与RTF的行为不同。



另一个问题。您不能在Web应用程序中使用Office Interop。它将在您的DEV计算机上运行,​​但在将其部署到Web服务器时会失败。非交互式(即:非交互式桌面上的服务器应用程序)环境不支持Office。



在RTF文档中,图像被编码和嵌入在文件本身。 HTML无法正常工作。嗯,实际上并不是这样,因为这会大量膨胀HTML。



网上有转换器会说将RTF转换成HTML!,但它们通常只有使用字体格式的文本,如斜体和粗体,有些甚至处理简单的表格。我不知道有哪个处理图像。



但是,在所有情况下,你都会得到一个HTML版本的RTF文档,它不会表现或完全呈现与RTF文档相同。
Yeah, this is not so simple. YOu're NOT going to get a perfect reproduction of the RTF document in HTML. RFT is not HTML. HTML does not behave the same way as RTF.

Another problem. You cannot use Office Interop in a web application. It'll work on your DEV machine but fail when you deploy it to a web server. Office is not supported in a non-interactive (i.e.: server app on a non-interactive desktop) environment.

In an RTF document, the images are encoded and embedded in the document itself. HTML doesn't work that way. Well, not practically anyway as this will bloat the HTML massively.

There are converters on the web that will say "Convert RTF to HTML!", but they usually only work with font formatted text, like italic and bold, some even handle simple tables. I don't know of one that handles images.

But, in all cases, you get an HTML version of the RTF document, which does NOT behave or render exactly the same as the RTF document.


这篇关于使用存储在SQL数据库中的图像检索rtf文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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