2017-09-18 11 views
0

Rubyを使用して.docxファイルを開いて読み込み、テキストとオブジェクト/画像の一部を抽出して別の(.docx以外の)ファイルに保存しようとしています。私が代わりに行う場合Ruby:docxファイルから画像とオブジェクトを解析/抽出する

zip = Zip::File.open file_path 
doc = zip.find_entry("word/document.xml") 
xml = Nokogiri::XML.parse(doc.get_input_stream) 
wt = xml.root.xpath("//w:t", {"w" => 
"http://schemas.openxmlformats.org/wordprocessingml/2006/main"}) 

:鋸山を使用して

、私は正しくテキストを抽出し、経由して、私が欲しいのセクションにドキュメントの私の分割を行うことができる午前

xml.root.xpath("//w:body", {"w" => "http://schemas.openxmlformats.org/wordprocessingml/2006/main"}) 

私が見ることができますxmlのオブジェクトは次のようになります。

<w:object w:dxaOrig="1440" w:dyaOrig="400"> 
    <v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="[email protected]@[email protected]@[email protected]@[email protected]@5xe" filled="f" stroked="f"> 
     <v:stroke joinstyle="miter"/> 
     <v:formulas> 
     <v:f eqn="if lineDrawn pixelLineWidth 0"/> 
     <v:f eqn="sum @0 1 0"/> 
     <v:f eqn="sum 0 0 @1"/> 
     <v:f eqn="prod @2 1 2"/> 
     <v:f eqn="prod @3 21600 pixelWidth"/> 
     <v:f eqn="prod @3 21600 pixelHeight"/> 
     <v:f eqn="sum @0 0 1"/> 
     <v:f eqn="prod @6 1 2"/> 
     <v:f eqn="prod @7 21600 pixelWidth"/> 
     <v:f eqn="sum @8 21600 0"/> 
     <v:f eqn="prod @7 21600 pixelHeight"/> 
     <v:f eqn="sum @10 21600 0"/> 
     </v:formulas> 
     <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/> 
     <o:lock v:ext="edit" aspectratio="t"/> 
    </v:shapetype> 
    <v:shape id="_x0000_i1025" type="#_x0000_t75" style="width:1in;height:20.4pt" o:ole=""> 
     <v:imagedata r:id="rId4" o:title=""/> 
    </v:shape> 
    <o:OLEObject Type="Embed" ProgID="Equation.DSMT4" ShapeID="_x0000_i1025" DrawAspect="Content" ObjectID="_1563800156" r:id="rId5"/> 
    </w:object> 

後でhtmlで表示するために使用することができます。 svgに変換すると、htmlのテキストと一緒に表示することができます。

ありがとうございました。

答えて

0

はそれはそれは、MSDNにUsing the Formulas Elementから例に対してそれを比較し、VMLかもしれないようになっています。すべてのものが何であるかに目を通すためにVML specificationにそのページのリンクがあり

<v:shape style='width:1in;height:1in;' strokecolor="red" 
strokeweight="2pt" coordsize="21600,21600" adj="17520" 
path="m10800,0qx0,10800,10800,21600,21600,10800,10800,0xe 
m7340,6445qx6215,7570,7340,8695,8465,7570,7340,6445xnfe 
m14260,6445qx13135,7570,14260,8695,15385,7570,14260,6445xnfe 
[email protected]@3,[email protected],[email protected]"> 
    <v:formulas> 
    <v:f eqn="sum 33030 0 #0"/> 
    <v:f eqn="prod #0 4 3"/> 
    <v:f eqn="prod @0 1 3"/> 
    <v:f eqn="sum @1 0 @2"/> 
    </v:formulas> 
</v:shape> 

です、しかし、あらかじめ書かれたツールについては、私はそれについて何か質問がありますが、ほとんど見つけられません。そのほとんどは重複して表示されているように見えるか、または何らかの方法ですべてを参照します。質問Are there any tools to convert legacy VML to SVG?

関連する問題