الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

Convert Ms-word Document To Html File

بدأه server_programmer في 26 أغسطس 2008 · 3 رد · 1,567 مشاهدة · في Microsoft Visual Basic.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

الأخوة الأكارم

بعد التحية

عندي مشكلة بايخة شوي و أحب أشارككم فيها يمكن لعلي ألاقي حل ‏

الية المشكلة؟

هي طلب بايخ بمعنى الكلمة ‏

و تتلخص المشكلة في ان المستخدمين في جهة معينة حابين يفتحوا مستندات وورد (المستندات التي تحتوي على بعض الكلمات) من ‏خلال برنامج انا عاملة لهم.‏

و بعد ان يتم فتح الملف فانهم حابين ان يقوم الوورد بتحديد هذة الكلمات تماما كما يحدث عندما نبحث عن كلمات معينة من داخل الوورد ‏من خلال أمر البحث ‏Ctrl+F‏ و تظليلها‏

طريقة فتح المستند كانت كالتالي

using Word.Application
‎=========================‎
Inorder to open word document using vb.net,your project should contain a reference to the Microsoft Word 10.0 ‎Object Library. You may need to use a different library if you have a different version of Word. ‎

‎	Dim file_name As String
‎	Dim file_path As String
‎	Dim file_title As String
‎	Dim word_server As Word.Application

‎	Cursor = System.Windows.Forms.Cursors.WaitCursor
‎	Application.DoEvents()‎

‎	file_name = txtFileName.Text
‎	file_title = file_name.Substring(file_name.LastIndexOf("\") + 1)‎
‎	file_path = file_name.Substring(0, file_name.LastIndexOf("\"))‎

‎	word_server = New Word.Application()‎
‎	word_server.ChangeFileOpenDirectory(file_path)‎
‎	word_server.Documents.Open( _‎
‎		FileName:=file_title, _‎
‎		ConfirmConversions:=False, _‎
‎		ReadOnly:=False, _‎
‎		AddToRecentFiles:=False, _‎
‎		PasswordDocument:="", _‎
‎		PasswordTemplate:="", _‎
‎		Revert:=False, _‎
‎		WritePasswordDocument:="", _‎
‎		WritePasswordTemplate:="", _‎
‎		Format:=Word.WdOpenFormat.wdOpenFormatAuto)‎
‎	word_server.Visible = True
‎	Cursor = System.Windows.Forms.Cursors.Default

‎' References:‎
‎'http://www.eggheadcafe.com/community/aspnet/14/10014762/using-wordapplication.aspx
‎'http://www.vbdotnetheaven.com/UploadFile/mgold/WordDocument04182005081441AM/WordDocument.aspx

و بعد مناقشة المشكلة ‏

وجدت أن برنامج الوورد لا يستطيع تحديد أكثر من نص في المرة الواحدة لذلك فأن تحويل المستند لصيغة ملف ‏HTML‏ هي الأنسب‏

و هنا ظهرت المشكلة التالية و هي ‏

كيف يمكن تحويل ملف الوورد لملف ‏HTML‏ و التي لا أعرف كيف يمكن ان تتم حصوصا أني حاولت فتح أي ملف وورد من خلال ‏الكائن ‏StreemReader‏ و لكن النتيجة كانت نص مشفر ليس لة معنى‏

الرجاء المساعدة

:wacko:

وفوق كل ذي علم عليم

http://www.leaderstechnology.com

-------------------------------

#2

جرب أخى هذة المكونات

من هنا

أصفق أو لا أصفق فخلفي كتلة شحم تصفق وبعض المساحيق كانت تصفق وجاري يصفق وأسأل .. هل أعجبته الرواية؟ يبحلق ثم يلكز جنبي ويمضي يصفق أصفق أو لا أصفق أمامي كل الرؤوس تصفق وخلفي كل الصفوف تصفق أتى مارد شدني من يدي وتساءل لم لا تصفق تصايح كل الحضور اطردوه تحسست عقلي اطردوه أفقت لنفسي طريداً طريد فصفقت حتى انقطاع الوريد حتى انقطاع الوريد أصفق من أجل ذاك الذي لايصفق

#3

اعتقد لو تستخدم Word2007 سيكون الامر سهلا ، لان ملف وورد 2007 هو ملف مضغوط به ملفات xml عدة ،

#4

قم بفتح ملف Word عن طريق RichTextBox ثم حوله إلى HTML عن طريق الكود التالي

Public Function ConvertToHTML(ByVal Box As RichTextBox) As String
		' Takes a RichTextBox control and returns a
		' simple HTML-formatted version of its contents
		Dim strHTML As String
		Dim strColour As String
		Dim blnBold As Boolean
		Dim blnItalic As Boolean
		Dim strFont As String
		Dim shtSize As Short
		Dim lngOriginalStart As Long
		Dim lngOriginalLength As Long
		Dim intCount As Integer
		' If nothing in the box, exit
		If Box.Text.Length = 0 Then Exit Function
		' Store original selections, then select first character
		lngOriginalStart = 0
		lngOriginalLength = Box.TextLength
		Box.Select(0, 1)
		' Add HTML header
		strHTML = "<html>"
		' Setup initial parameters
		strColour = Box.SelectionColor.ToKnownColor.ToString
		blnBold = Box.SelectionFont.Bold
		blnItalic = Box.SelectionFont.Italic
		strFont = Box.SelectionFont.FontFamily.Name
		shtSize = Box.SelectionFont.Size
		' Include first 'style' parameters in the HTML
		strHTML += "<span style=""font-family: " & strFont & _
		  "; font-size: " & shtSize & "pt; color: " & strColour & """>"
		' Include bold tag, if required
		If blnBold = True Then
			strHTML += "<b>"
		End If
		' Include italic tag, if required
		If blnItalic = True Then
			strHTML += "<i>"
		End If
		' Finally, add our first character
		strHTML += Box.Text.Substring(0, 1)
		' Loop around all remaining characters
		For intCount = 2 To Box.Text.Length
			' Select current character
			Box.Select(intCount - 1, 1)
			' If this is a line break, add HTML tag
			If Box.Text.Substring(intCount - 1, 1) = Convert.ToChar(10) Then
				strHTML += "<br>"
			End If
			' Check/implement any changes in style
			If Box.SelectionColor.ToKnownColor.ToString <> strColour _
				Or Box.SelectionFont.FontFamily.Name <> strFont Or _
				Box.SelectionFont.Size <> shtSize Then
				strHTML += "</span><span style=""font-family: " _
				  & Box.SelectionFont.FontFamily.Name & _
				  "; font-size: " & Box.SelectionFont.Size & _
				  "pt; color: " & _
				  Box.SelectionColor.ToKnownColor.ToString & """>"
			End If
			' Check for bold changes
			If Box.SelectionFont.Bold <> blnBold Then
				If Box.SelectionFont.Bold = False Then
					strHTML += "</b>"
				Else
					strHTML += "<b>"
				End If
			End If
			' Check for italic changes
			If Box.SelectionFont.Italic <> blnItalic Then
				If Box.SelectionFont.Italic = False Then
					strHTML += "</i>"
				Else
					strHTML += "<i>"
				End If
			End If
			' Add the actual character
			strHTML += Mid(Box.Text, intCount, 1)
			' Update variables with current style
			strColour = Box.SelectionColor.ToKnownColor.ToString
			blnBold = Box.SelectionFont.Bold
			blnItalic = Box.SelectionFont.Italic
			strFont = Box.SelectionFont.FontFamily.Name
			shtSize = Box.SelectionFont.Size
		Next
		' Close off any open bold/italic tags
		If blnBold = True Then strHTML += "</b>"
		If blnItalic = True Then strHTML += "</i>"
		' Terminate outstanding HTML tags
		strHTML += "</span></html>"
		' Restore original RichTextBox selection
		Box.Select(lngOriginalStart, lngOriginalLength)
		' Return HTML
		Return strHTML
	End Function

تم تعديل هذه المشاركة بواسطة MiCcSoft في 2 سبتمبر 2008 في 02:20

مواضيع مشابهة