سؤال

Word 2007 يحفظ لها وثائق .docx الذي هو في الحقيقة ملف مضغوط مع مجموعة من الأشياء بما في ذلك ملف xml مع الوثيقة.

أريد أن تكون قادرة على اتخاذ .الملف docx وأسقطه في مجلد في بي asp.net التطبيق على شبكة الإنترنت و قد رمز فتح .الملف docx وتقديم (xml جزء من) المستند كصفحة ويب.

لقد تم البحث على الويب للحصول على مزيد من المعلومات حول هذا ولكن حتى الآن لم أجد من ذلك بكثير.أسئلتي هي:

  1. هل (أ) استخدام XSLT لتحويل XML أو HTML أو (ب) استخدام xml التلاعب المكتبات .صافي (مثل XDocument و XElement في 3.5) لتحويل HTML أو (ج) ؟
  2. هل تعرف من أي المكتبات مفتوحة المصدر/المشاريع التي فعلت هذه التي يمكن أن تستخدم كنقطة انطلاق?

وذلك بفضل!

هل كانت مفيدة؟

المحلول

جرب هذا بعد?لا أعلم ولكن قد يكون ما كنت تبحث عن.

نصائح أخرى

كتبت mammoth.js, التي هي مكتبة جافا سكريبت تحويل ملفات docx إلى HTML.إذا كنت تريد أن تفعل التقديم من جانب الخادم في .صافي ، هناك أيضا .النسخة الصافية من الماموث المتاحة على NuGet.

الماموث يحاول إنتاج نظيفة HTML من خلال النظر في المعلومات الدلالية-على سبيل المثال ، رسم أنماط الفقرة في كلمة (مثل Heading 1) إلى العلامات المناسبة و أسلوب في HTML/CSS (مثل <h1>).إذا كنت تريد شيئا التي تنتج الدقيق النسخة المرئية ، ثم العملاقة ربما ليست لك.إذا كان لديك شيء بالفعل منظم جيدا و تريد تحويل ذلك إلى مرتبة HTML ، الماموث قد تفعل خدعة.

Word 2007 API التي يمكنك استخدامها لتحويل HTML.وهنا بعد أن يتحدث عن ذلك http://msdn.microsoft.com/en-us/magazine/cc163526.aspx.يمكنك العثور على وثائق حول API, ولكن أتذكر أن هناك تحويلها إلى HTML وظيفة في API.

هذا القانون سوف يساعد على تحويل .docx ملف نص

function read_file_docx($filename){

    $striped_content = '';
    $content = '';

    if(!$filename || !file_exists($filename)) { echo "sucess";}else{ echo "not sucess";}

    $zip = zip_open($filename);

    if (!$zip || is_numeric($zip)) return false;

    while ($zip_entry = zip_read($zip)) {

        if (zip_entry_open($zip, $zip_entry) == FALSE) continue;

        if (zip_entry_name($zip_entry) != "word/document.xml") continue;

        $content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));

        zip_entry_close($zip_entry);
    }// end while

    zip_close($zip);

    //echo $content;
    //echo "<hr>";
    //file_put_contents('1.xml', $content);     

    $content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);
    $content = str_replace('</w:r></w:p>', "\r\n", $content);
     //header("Content-Type: plain/text");


    $striped_content = strip_tags($content);


      $striped_content = preg_replace("/[^a-zA-Z0-9\s\,\.\-\n\r\t@\/\_\(\)]/","",$striped_content);

    echo nl2br($striped_content); 
}

أنا باستخدام إمكانية التشغيل المتداخل.هذا هو إلى حد ما problamatic ولكن يعمل بشكل جيد في معظم الحالات.

using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Word;

هذا واحد بإرجاع قائمة html تحويل الوثائق المسار

public List<string> GetHelpDocuments()
    {

        List<string> lstHtmlDocuments = new List<string>();
        foreach (string _sourceFilePath in Directory.GetFiles(""))
        {
            string[] validextentions = { ".doc", ".docx" };
            if (validextentions.Contains(System.IO.Path.GetExtension(_sourceFilePath)))
            {
                sourceFilePath = _sourceFilePath;
                destinationFilePath = _sourceFilePath.Replace(System.IO.Path.GetExtension(_sourceFilePath), ".html");
                if (System.IO.File.Exists(sourceFilePath))
                {
                    //checking if the HTML format of the file already exists. if it does then is it the latest one?
                    if (System.IO.File.Exists(destinationFilePath))
                    {
                        if (System.IO.File.GetCreationTime(destinationFilePath) != System.IO.File.GetCreationTime(sourceFilePath))
                        {
                            System.IO.File.Delete(destinationFilePath);
                            ConvertToHTML();
                        }
                    }
                    else
                    {
                        ConvertToHTML();
                    }

                    lstHtmlDocuments.Add(destinationFilePath);
                }
            }


        }
        return lstHtmlDocuments;
    }

و هذا واحد لتحويل وثيقة html.

private void ConvertToHtml()
    {
        IsError = false;
        if (System.IO.File.Exists(sourceFilePath))
        {
            Microsoft.Office.Interop.Word.Application docApp = null;
            string strExtension = System.IO.Path.GetExtension(sourceFilePath);
            try
            {
                docApp = new Microsoft.Office.Interop.Word.Application();
                docApp.Visible = true;

                docApp.DisplayAlerts = WdAlertLevel.wdAlertsNone;
                object fileFormat = WdSaveFormat.wdFormatHTML;
                docApp.Application.Visible = true;
                var doc = docApp.Documents.Open(sourceFilePath);
                doc.SaveAs2(destinationFilePath, fileFormat);
            }
            catch
            {
                IsError = true;
            }
            finally
            {
                try
                {
                    docApp.Quit(SaveChanges: false);

                }
                catch { }
                finally
                {
                    Process[] wProcess = Process.GetProcessesByName("WINWORD");
                    foreach (Process p in wProcess)
                    {
                        p.Kill();
                    }
                }
                Marshal.ReleaseComObject(docApp);
                docApp = null;
                GC.Collect();
            }
        }
    }

مقتل كلمة ليست متعة ، ولكن لا يمكن أن يتركها معلقة هناك كتلة الآخرين, أليس كذلك ؟

في شبكة الإنترنت/html لا تجعل html iframe.

هناك المنسدلة التي تحتوي على قائمة وثائق مساعدة.القيمة هو المسار إلى إصدار html من النص اسم المستند.

private void BindHelpContents()
    {
        List<string> lstHelpDocuments = new List<string>();
        HelpDocuments hDoc = new HelpDocuments(Server.MapPath("~/HelpDocx/docx/"));
        lstHelpDocuments = hDoc.GetHelpDocuments();
        int index = 1;
        ddlHelpDocuments.Items.Insert(0, new ListItem { Value = "0", Text = "---Select Document---", Selected = true });

        foreach (string strHelpDocument in lstHelpDocuments)
        {
            ddlHelpDocuments.Items.Insert(index, new ListItem { Value = strHelpDocument, Text = strHelpDocument.Split('\\')[strHelpDocument.Split('\\').Length - 1].Replace(".html", "") });
            index++;
        }
        FetchDocuments();

    }

على اختيار مؤشر تغيرت ، فمن renedred إلى الإطار

    protected void RenderHelpContents(object sender, EventArgs e)
    {
        try
        {
            if (ddlHelpDocuments.SelectedValue == "0") return;
            string strHtml = ddlHelpDocuments.SelectedValue;
            string newaspxpage = strHtml.Replace(Server.MapPath("~/"), "~/");
            string pageVirtualPath = VirtualPathUtility.ToAbsolute(newaspxpage);// 
            documentholder.Attributes["src"] = pageVirtualPath;
        }
        catch
        {
            lblGError.Text = "Selected document doesn't exist, please refresh the page and try again. If that doesn't help, please contact Support";
        }
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top