我需要做的是......讀取一個word文件並根據字體的屬性在它們之前添加一個標籤,以區分它作爲標題或 但是,我需要使用Perl來做到這一點.. 是否有可能? 任何幫助將不勝感激。 謝謝!使用perl查找MS-Word文檔的字體屬性
0
A
回答
2
我需要更多的信息來幫助你確定的話,你需要處理。在我的例子我只是在尋找我有這個代碼的工作文字一些(this is my *.docx file)
#!/usr/bin/perl
use Modern::Perl;
use Win32::OLE;
use Win32::OLE qw(in with);
use Win32::OLE::Variant;
use Win32::OLE::Const 'Microsoft Word';
$Win32::OLE::Warn = 3;
print "Starting Word\n";
my $Word = Win32::OLE->GetActiveObject('Word.Application') ||
Win32::OLE->new('Word.Application');
$Word->{'Visible'} = 1;
$Word->{DisplayAlerts} = 0;
my $File = $Word->Documents->Open("./fonts.docx") or die Win32::OLE->LastError;
$Word->Selection->HomeKey(wdStory);
$Word->Selection->Find->{'Text'} = 'Some';
$Word->Selection->Find->Execute();
say "Font size: [", $Word->Selection->Font->Size(), "]";
say "Font name: [", $Word->Selection->Font->Name(), "]";
$Word->Quit;
0
嘗試使用OLE自動化,Win32::OLE模塊是有幫助的。 這種方式需要更深入的Word OLE api知識。
4
@Nikita,這將給你的公司如何做的詳細視圖:
#!/usr/bin/perl
use strict;
use warnings;
use Win32::OLE::Const 'Microsoft Word';
#$Win32::OLE::CP = CP_UTF8;
binmode STDOUT, 'encoding(utf8)';
# OPEN FILE SPECIFIED AS FIRST ARGUMENT
my $fname=$ARGV[0];
my $fnameFullPath = `cygpath.exe -wa $fname`;
$fnameFullPath =~ s/\\/\\\\/g;
$fnameFullPath =~ s/\s*$//;
unless (-e $fnameFullPath) { print "Error: File did not exists\n"; exit 1;}
# STARTING OLE
my $Word = Win32::OLE->GetActiveObject('Word.Application')
|| Win32::OLE->new('Word.Application','Quit')
or die Win32::OLE->LastError();
$Word->{'Visible'} = 0;
my $doc = $Word->Documents->Open($fnameFullPath);
my $paragraphs = $doc->Paragraphs() ;
my $enumerate = new Win32::OLE::Enum($paragraphs);
# PROCESSING PARAGRAPHS
while(defined(my $paragraph = $enumerate->Next())) {
my $text = $paragraph->{Range}->{Text};
my $sel = $Word->Selection;
my $font = $sel->Font;
if ($font->{Size} == 18){
print "Text: ", $text, "\n";
print "Font Bold: ", $font->{Bold}, "\n";
print "Font Italic: ", $font->{Italic}, "\n";
print "Font Name: ", $font->{Name}, "\n";
print "Font Size: ", $font->{Size}, "\n";
print "=========\n";
}
}
# CLOSING OLE
$Word->ActiveDocument->Close ;
$Word->Quit;
輸出將是這樣的:
Text: This is a doc file containing different fonts and size, document also contain header and footer (Font: TNR, Size: 18) Font Bold: 0 Font Italic: 0 Font Name: Times New Roman Font Size: 18 ========= Text: This is a Perl example (Font TNR, Size: 12) Font Bold: 0 Font Italic: 0 Font Name: Times New Roman Font Size: 18 ========= Text: This is a Python example(Font: Courier New, Size: 10) Font Bold: 0 Font Italic: 0 Font Name: Times New Roman Font Size: 18 =========
相關問題
- 1. C#xml文檔按屬性查找值
- 2. 如何使用Xpath 1.0從XML文檔中查找max屬性
- 3. 強制MSWord使用設置字體打開文檔(忽略文件內的文檔)
- 4. 使用perl的PDF中的字體顏色屬性PDF ::創建
- 5. 如何使用Perl和CAM :: PDF閱讀PDF文檔屬性?
- 6. 在Jekyll中定製液體標籤以查找屬性的集合文檔
- 7. 用貓鼬更新文檔(更新文檔屬性的屬性)
- 8. 使用golang的部分屬性的mgo找不到文檔
- 9. MarkLogic 8 - XQuery - cts查詢按值查找文檔屬性
- 10. css字體屬性vs文本屬性
- 11. 通過屬性值查找XML文檔中的節點
- 12. 在AdminDirectory.Users.list響應對象中查找trigger_event屬性的文檔
- 13. 使用實體框架的屬性數據庫查找(計數)
- 14. RavenDB移除屬性的查詢文檔
- 15. 查找文檔頁面上的文字
- 16. 如何使用存儲文檔中的屬性運行查詢?
- 17. 如何替換MsWord文檔中的標籤使用php
- 18. 如何使用貓鼬將其他屬性添加到mongoDB中查找文檔?
- 19. 在XML文檔中查找屬性並使用PHP輸出子節點
- 20. 如何在iPhone應用程序中使用CGPDFScanner查找pdf文檔字體?
- 21. 使用屬性獲取Filenet文檔
- 22. 使用C#屬性和文檔
- 23. 字體屬性
- 24. 查找的文檔
- 25. 在大型XML文檔中查找特定屬性
- 26. 查找文檔
- 27. 查找文檔
- 28. 查找文檔
- 29. VBA查找替換MSWord 2013的宏
- 30. JavaScript:文檔屬性
但cudnt找到的所有段落屬性。 Neways謝謝! – Nikita 2013-03-22 06:05:22
感謝sinan的編輯 – 2013-03-25 10:38:07