Procedimento Sinan Unur funziona bene.
Tuttavia, ho avuto un crash con i file che stavo trasformando.
Un altro metodo è quello di utilizzare Win32 :: OLE e Win32 :: Appunti come ad esempio:
- Aprire il documento di Word
- selezionare tutto il testo
- Copia nella Clipboard
- Stampa la contenuto di Appunti in un file txt
- Svuota gli Appunti e chiude il documento Word
In base alla sceneggiatura di Sigvald Refsu in http://computer-programming-forum.com/53-perl/c44063de8613483b.htm, ho trovato il seguente script.
Nota: ho scelto di salvare il file txt con lo stesso nome base del file.file docx e nella stessa cartella, ma questo può essere facilmente modificato
###########################################
use strict;
use File::Spec::Functions qw(catfile);
use FindBin '$Bin';
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Word';
use Win32::Clipboard;
my $monitor_word=0; #set 1 to watch MS Word being opened and closed
sub docx2txt {
##Note: the path shall be in the form "C:\dir\ with\ space\file.docx";
my $docx_file=shift;
#MS Word object
my $Word = Win32::OLE->new('Word.Application', 'Quit') or die "Couldn't run Word";
#Monitor what happens in MS Word
$Word->{Visible} = 1 if $monitor_word;
#Open file
my $Doc = $Word->Documents->Open($docx_file);
with ($Doc, ShowRevisions => 0); #Turn of revision marks
#Select the complete document
$Doc->Select();
my $Range = $Word->Selection();
with ($Range, ExtendMode => 1);
$Range->SelectAll();
#Copy selection to clipboard
$Range->Copy();
#Create txt file
my $txt_file=$docx_file;
$txt_file =~ s/\.docx$/.txt/;
open(TextFile,">$txt_file") or die "Error while trying to write in $txt_file (!$)";
printf TextFile ("%s\n", Win32::Clipboard::Get());
close TextFile;
#Empty the Clipboard (to prevent warning about "huge amount of data in clipboard")
Win32::Clipboard::Set("");
#Close Word file without saving
$Doc->Close({SaveChanges => wdDoNotSaveChanges});
# Disconnect OLE
undef $Word;
}
spero che ti può ti aiuta.
fonte
2014-03-13 11:21:05
fintanto che può essere automatizzato attraverso un'attività pianificata su un PC Windows, non importa se la parola è aperta .... ripara male la domanda – CheeseConQueso