Excel で開くスタイルを含む xml スプレッドシートを作成しようとしています。
これは私のコードです:
res = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
xml.Workbook 'xmlns' => "urn:schemas-microsoft-com:office:spreadsheet",
'xmlns:o' => "urn:schemas-microsoft-com:office:office",
'xmlns:x' => "urn:schemas-microsoft-com:office:excel",
'xmlns:html' => "http://www.w3.org/TR/REC-html40",
'xmlns:ss' => "urn:schemas-microsoft-com:office:spreadsheet" do
xml.WorksheetOptions "xmlns" => "urn:schemas-microsoft-com:office:excel" do
xml.PageSetup do
xml.Layout "x:Orientation" => "Landscape"
xml.Header "x:Data" => "&LLeft side&CCenter&R&D &T"
xml.Footer "x:Data" => "&CPage: &P / &N"
end
xml.Unsynced
xml.FitToPage
xml.Print do
xml.FitHeight 20
xml.ValidPrinterInfo
xml.Scale 90
xml.HorizontalResolution -4
xml.VerticalResolution -4
end
xml.Zoom 125
xml.PageLayoutZoom 0
xml.Selected
xml.Panes do
xml.Pane do
xml.Number 3
xml.ActiveRow 8
xml.ActiveCol 4
end
end
xml.ProtectObjects "False"
xml.ProtectScenarios "False"
xml.AllowFormatCells
xml.AllowSizeCols
xml.AllowSizeRows
xml.AllowSort
xml.AllowFilter
xml.AllowUsePivotTables
end
end
end.to_xml
puts res
私はこれを何年もの間、機能するテンプレートとして使用していました (以前は bunlder のビルダーを使用していましたが、現在は遅すぎます)。Nokogiri に切り替えたので、機能しなくなりました。基本的にこれ:タグ"xmlns" => "urn:schemas-microsoft-com:office:excel"
内のWorksheetOptions
get は無視され、ドキュメントに追加されません。実際の結果は次のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<WorksheetOptions>
<PageSetup>
<Layout x:Orientation="Landscape"/>
<Header x:Data="&LLeft side&CCenter&R&D &T"/>
<Footer x:Data="&CPage: &P / &N"/>
</PageSetup>
<Unsynced/>
<FitToPage/>
<Print>
<FitHeight>20</FitHeight>
<ValidPrinterInfo/>
<Scale>90</Scale>
<HorizontalResolution>-4</HorizontalResolution>
<VerticalResolution>-4</VerticalResolution>
</Print>
<Zoom>125</Zoom>
<PageLayoutZoom>0</PageLayoutZoom>
<Selected/>
<Panes>
<Pane>
<Number>3</Number>
<ActiveRow>8</ActiveRow>
<ActiveCol>4</ActiveCol>
</Pane>
</Panes>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
<AllowFormatCells/>
<AllowSizeCols/>
<AllowSizeRows/>
<AllowSort/>
<AllowFilter/>
<AllowUsePivotTables/>
</WorksheetOptions>
</Workbook>
xmlns
この行の属性として何か他のものを書くと、xml.WorksheetOptions "xmlns" => "urn:schemas-microsoft-com:office:excel" do
それは機能し、ドキュメントに正しく追加されます。
これは間違っています。明らかに、その属性が欠落している場合、Excel はページを適切に設定しません。これはノコギリの正しい行動ですか?
そうである場合、ドキュメントに正しいページ レイアウトを Excel に適用させる他の方法はありますか?
これは、例に含めなかった別のタグで発生します。そうしないと、長すぎます。これはもう 1 つです: xml.DocumentProperties("xmlns" => "urn:schemas-microsoft-com:office:office") do
.