1つのOpenOffice Writerファイルから別のOpenOffice Writerファイルにテーブルの書式をコピーしようとしています...私はスタイルの名前を2番目のドキュメントに書いています。スタイルデータではありません。OpenOffice :: OODocを使用してテーブルスタイルを転送する
私はデバッガで$style
オブジェクトを検査する場合、それが表示され、特にので、私はこれがodfContainer
の'styles'
一部とは何かを持っていると思われるが、私は2番目の文書にこれを書き込む方法については明らかではありませんよ'content'
部分をロードした$doc
オブジェクトと同じになるようにします。デバッガの内部で検査する際にここで
は、私がこれまで持っているものだ...私は、セルのスタイルとして'Table1.A1'
をロードしています
#! /usr/bin/perl
use warnings;
use strict;
use OpenOffice::OODoc;
my $file='mytest.odt';
my $outfile='doc2.odt';
# load input file
my $container = odfContainer("$file");
$container->raw_export("styles.xml");
my $doc = odfDocument
(
container => $container,
part => 'content'
);
my $style = odfDocument
(
container => $container,
part => 'styles'
);
# load output file
my $container2 = odfContainer($outfile, create => 'text');
$container2->raw_import("styles.xml");
my $doc2 = odfDocument
(
container => $container2,
part => 'content'
);
# Load table from 'mytest.odt'
my $table=$doc->getTable(0);
# Get style from first cell in $table
my $headerstyle=$doc->getStyle($doc->getCell($table, 0, 0));
# Create table in $doc2
my $newtable=$doc2->appendTable('newtable', 1, 1, 'table-style' => $doc->getStyle($table));
# Set style of first cell in $newtable to 'Table1.A1'
$doc2->cellStyle($newtable, 0, 0, 'Table1.A1');
# Write 'doc2.odt' to disk
$container2->save;
理由は、私が$table
の奥深く次見つけたことです。私は属性が、私がコピーしようとしている、と私はまた'getStyle'
方法はstyle::name
属性を返すことを実験から知っているものと一致...私はちょうど設定から取得する方法を知らないことを知っている
'next_sibling' => OpenOffice::OODoc::Element=HASH(0x102029250)
'att' => HASH(0x102029180)
'style:family' => 'table-cell'
'style:name' => 'Table1.A1'
'empty' => 0
'first_child' => OpenOffice::OODoc::Element=HASH(0x1020294a0)
'att' => HASH(0x102029200)
'fo:background-color' => '#cccccc'
'fo:border' => '0.0069in solid #000000'
'fo:padding-bottom' => '0in'
'fo:padding-left' => '0.075in'
'fo:padding-right' => '0.075in'
'fo:padding-top' => '0in'
'style:vertical-align' => 'top'
'style:writing-mode' => 'lr-tb'
属性を使用して、実際に基礎となるデータを新しい文書に書き込むことになります。
編集:OpenOfficeのファイルを解凍
、私はいくつかのXMLファイルを取得:
- のsettings.xml
- のstyles.xml
- content.xml
など
Th OdfContainer
のe 'styles'
および'content'
の部分は、styles.xmlおよびcontent.xmlに対応します。 Styles.xmlは、ODFファイルのさまざまなヘッダーレベルのスタイル情報を含むcssファイルのようなものです。 Content.xmlには、HTML文書のCSSヘッダーによく似たスタイル情報も含まれています。
これは、odtファイルから抽出されたcontent.xmlのスタイル部分です(実際はそれと同じように...私は元のファイルを保存しませんでした)。
<?xml version="1.0" encoding="utf-8"?>
<office:document-content>
...
<office:automatic-styles>
<style:style style:name="Table6" style:family="table" style:master-page-name="First_20_Page">
<style:table-properties style:width="6.9208in" style:page-number="auto" table:align="left" style:writing-mode="lr-tb" />
</style:style>
<style:style style:name="Table6.A" style:family="table-column">
<style:table-column-properties style:column-width="1.2729in" />
</style:style>
<style:style style:name="Table6.B" style:family="table-column">
<style:table-column-properties style:column-width="3.2604in" />
</style:style>
<style:style style:name="Table6.C" style:family="table-column">
<style:table-column-properties style:column-width="2.3875in" />
</style:style>
<style:style style:name="Table6.1" style:family="table-row">
<style:table-row-properties style:min-row-height="0.1597in" style:keep-together="true" fo:keep-together="auto" />
</style:style>
<style:style style:name="Table6.A1" style:family="table-cell">
<style:table-cell-properties
style:vertical-align="bottom"
fo:background-color="#cccccc"
fo:padding-left="0.075in"
fo:padding-right="0.075in"
fo:padding-top="0in"
fo:padding-bottom="0in"
fo:border-left="0.0069in solid #000000"
fo:border-right="none"
fo:border-top="0.0069in solid #000000"
fo:border-bottom="0.0069in solid #000000"
style:writing-mode="lr-tb">
<style:background-image />
</style:table-cell-properties>
</style:style>
...
- スタイル:名= "表6" は、現在のテーブルのスタイルを説明し、
- スタイル:名= "Table6.Aは" この表の列Aのスタイルを説明し、
- スタイル:名=「Table6.A1」は、セルA1
のスタイルは、入力ファイルの「content.xml」セクションの生の輸出を行って説明し、出力ファイル内生インポートが転送データを行います1つのファイルからもう片方に。
#! /usr/local/bin/perl
use warnings;
use strict;
use OpenOffice::OODoc;
my $infile=$ARGV[0];
my $outfile='outfile.odt';
my $incontainer = odfContainer($infile);
$incontainer->raw_export("content.xml");
my $outcontainer = odfContainer($outfile, create => 'text');
$outcontainer->raw_import("content.xml");
$outcontainer->save;
oodoc.pl infile.odt
を実行し、outfile.odtを解凍してコンテンツを検査します。XMLはスタイルが正常に転送されたことを示してい:今、これが行われていることを、私は実際に$outcontainer
にセルスタイルをロードして使用する必要があります
<style:style style:name="Table1" style:family="table">
<style:table-properties style:width="6.925in" table:align="margins" />
</style:style>
<style:style style:name="Table1.A" style:family="table-column">
<style:table-column-properties
style:column-width="2.3083in"
style:rel-column-width="21845*" />
</style:style>
<style:style style:name="Table1.A1" style:family="table-cell">
<style:table-cell-properties
fo:background-color="#cccccc"
fo:padding="0.0382in"
fo:border-left="0.0007in solid #000000"
fo:border-right="none"
fo:border-top="0.0007in solid #000000"
fo:border-bottom="0.0007in solid #000000">
<style:background-image />
</style:table-cell-properties>
</style:style>
。
私はperlのユーザーではありませんよ、私はPHPとC++で同じようにしました。これは実際には次のようになります:ドキュメントを取って、スタイルや物をラップし、データドキュメントのセル値を新しいデータに置き換え、パッケージ全体を新しいパッケージにまとめます。スタイルを変更したい場合は、もう少し複雑になります。私は個人的にはXMLを奇妙な再構成のために責めていますが、XMLは単純ではなく論理であることも知っています。とにかく...私はあなたにヒントをくれたことを願っています。自分でコーディングする必要があります。 –