Skip to content

Commit

Permalink
Some cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-q committed Feb 16, 2016
1 parent b4d1dfd commit 057a9ad
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 110 deletions.
46 changes: 14 additions & 32 deletions cdr_export.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,31 @@
use warnings;
use autodie;

use Getopt::Long;
use Pod::Usage;
use Getopt::Long qw(HelpMessage);
use FindBin;
use YAML qw(Dump Load DumpFile LoadFile);

use Win32::OLE qw(in);
use Win32::OLE::Const;
use Win32::OLE::Variant;
use Win32::OLE::NLS qw(:LOCALE :DATE);
use Win32::OLE::Const 'Corel - CorelDRAW 15.0 Type Library';

use Path::Class;
use File::Find::Rule;
use File::Spec;
use Win32::OLE::Const 'Corel - CorelDRAW';

$Win32::OLE::Warn = 3; # die on errors...

use Path::Tiny;
use File::Find::Rule;

#----------------------------------------------------------#
# GetOpt section
#----------------------------------------------------------#
# running options
my $dir = '.';

my $resolution = 300; # dpi
my $format = 'png';

my $man = 0;
my $help = 0;

GetOptions(
'help|?' => \$help,
'man' => \$man,
'd|dir=s' => \$dir,
'r|resolution=s' => \$resolution,
'f|format=s' => \$format,
) or pod2usage(2);

pod2usage(1) if $help;
pod2usage( -exitstatus => 0, -verbose => 2 ) if $man;
'help|?' => sub { HelpMessage(0) },
'dir|d=s' => \( my $dir = '.' ),
'resolution|r=s' => \( my $resolution = 300 ),
'format|f=s' => \( my $format = 'png' ),
) or HelpMessage(1);

#----------------------------------------------------------#
# init
Expand All @@ -61,7 +48,7 @@
}

for my $file (@files) {
$file = File::Spec->rel2abs($file);
$file = path($file)->absolute->stringify;
print $file, "\n";

$cs->FileOpen($file) or die "Cannot open file [$file]\n";
Expand Down Expand Up @@ -109,9 +96,8 @@
#$opt->{ResolutionX} = 97;
#$opt->{ResolutionY} = 97;
#
$doc->ExportBitmap( $export, cdrPNG, 1, 4, 0,
0, 72, 72, cdrUndefined , cdrUndefined, cdrUndefined, cdrUndefined, cdrUndefined);

$doc->ExportBitmap( $export, cdrPNG, 1, 4, 0, 0, 72, 72, cdrUndefined, cdrUndefined,
cdrUndefined, cdrUndefined, cdrUndefined );

$cs->FileClose;
}
Expand All @@ -134,7 +120,3 @@
$cda->Quit;

__END__
=head1 SYNOPSIS
perl corel_fig.pl -i Fig.S1.yaml
2 changes: 1 addition & 1 deletion collect_common_basic.pl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ =head1 SYNOPSIS
$tt->process( \$text, { data => \@data, }, $output ) or die Template->error;
print "$output\n";

system("perl $FindBin::Bin/./excel_table.pl -i $output");
system("perl $FindBin::Bin/excel_table.pl -i $output");

__END__
16 changes: 8 additions & 8 deletions collect_excel.pl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
use FindBin;
use YAML qw(Dump Load DumpFile LoadFile);

use List::MoreUtils qw(any all uniq zip);
use Path::Tiny;
use Set::Scalar;

use Win32::OLE qw(in);
use Win32::OLE::Const;
use Win32::OLE::Variant;
Expand All @@ -19,6 +15,10 @@

$Win32::OLE::Warn = 2; # die on errors...

use List::MoreUtils qw(any all uniq zip);
use Path::Tiny;
use Set::Scalar;

#----------------------------------------------------------#
# GetOpt section
#----------------------------------------------------------#
Expand All @@ -31,10 +31,10 @@ =head1 SYNOPSIS

GetOptions(
'help|?' => sub { HelpMessage(0) },
'f|file=s' => \my @files_xlsx,
's|sheet=s' => \my @sheetnames,
'n|name=s' => \my @newnames,
'o|output=s' => \( my $output = "collected.xlsx" ),
'file|f=s' => \my @files_xlsx,
'sheet|s=s' => \my @sheetnames,
'name|n=s' => \my @newnames,
'output|o=s' => \( my $output = "collected.xlsx" ),
) or HelpMessage(1);

#----------------------------------------------------------#
Expand Down
56 changes: 23 additions & 33 deletions corel_fig.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use warnings;
use autodie;

use Getopt::Long;
use Pod::Usage;
use Getopt::Long qw(HelpMessage);
use FindBin;
use YAML qw(Dump Load DumpFile LoadFile);

use Win32::OLE qw(in);
Expand All @@ -14,28 +14,27 @@
use Win32::OLE::Const 'Microsoft Excel';
use Win32::OLE::Const 'Corel - CorelDRAW';

use Path::Class;
use Set::Scalar;

$Win32::OLE::Warn = 2; # die on errors...

use Path::Tiny;
use Set::Scalar;

#----------------------------------------------------------#
# GetOpt section
#----------------------------------------------------------#
# running options
my $file_yaml = 'Fig.S1.yaml';

my $man = 0;
my $help = 0;
=head1 SYNOPSIS
GetOptions(
'help|?' => \$help,
'man' => \$man,
'i|input=s' => \$file_yaml,
) or pod2usage(2);
Don't work under CorelDraw X7. Use X6 or below.
perl corel_fig.pl -i Fig.S1.yaml
=cut

pod2usage(1) if $help;
pod2usage( -exitstatus => 0, -verbose => 2 ) if $man;
GetOptions(
'help|?' => sub { HelpMessage(0) },
'input|i=s' => \( my $file_yaml = 'Fig.S1.yaml' ),
) or HelpMessage(1);

#----------------------------------------------------------#
# init
Expand All @@ -52,8 +51,8 @@

# Excel files should be located in the same dir as the yaml file.
# cdr file will be named after yaml file.
$file_yaml = file($file_yaml)->absolute;
my $base_dir = $file_yaml->dir->stringify;
$file_yaml = path($file_yaml)->absolute;
my $base_dir = $file_yaml->parent->stringify;
my $cfile = $file_yaml->stringify;
$cfile =~ s/\.ya?ml$/\.cdr/;

Expand Down Expand Up @@ -84,8 +83,8 @@

# A4 210 * 297 mm
$cda->{ActivePage}->SetSize( 210, 297 );
$doc->{DrawingOriginX} = -105 + 5;
$doc->{DrawingOriginY} = 148.5 - 5;# give space for texts
$doc->{DrawingOriginX} = -105 + 5;
$doc->{DrawingOriginY} = 148.5 - 5; # give space for texts

#----------------------------------------------------------#
# Paste every charts
Expand All @@ -94,7 +93,7 @@
printf "[file: %s]\n", $filename;

# open xls file
my $efile = file( $base_dir, $filename )->stringify;
my $efile = path( $base_dir, $filename )->stringify;
if ( !-e $efile ) {
warn "File not exists: $efile\n";
next;
Expand Down Expand Up @@ -148,7 +147,7 @@
printf "[file: %s]\n", $filename;

# open xls file
my $efile = file( $base_dir, $filename )->stringify;
my $efile = path( $base_dir, $filename )->stringify;
if ( !-e $efile ) {
warn "File not exists: $efile\n";
next;
Expand Down Expand Up @@ -205,8 +204,8 @@
# my ( $x, $y ) = @{ $i->{pos} };
#
# printf "[file: %s]\n", $name;
#
# my $ffile = file( $base_dir, $name )->absolute->stringify;
#
# my $ffile = path( $base_dir, $name )->absolute->stringify;
# if ( !-e $ffile ) {
# warn "File not exists: $ffile\n";
# next;
Expand All @@ -223,7 +222,6 @@
# sleep 1;
#}


#----------------------------------------------------------#
# Write every texts
#----------------------------------------------------------#
Expand Down Expand Up @@ -267,11 +265,3 @@
$cda->Quit;

__END__
=head1 SYNOPSIS
perl corel_fig.pl -i Fig.S1.yaml
=head1 CAUTIONs
Don't work under CorelDraw X7. Use X6 or below.
14 changes: 7 additions & 7 deletions excel_table.pl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
use FindBin;
use YAML qw(Dump Load DumpFile LoadFile);

use Path::Class;
use Set::Scalar;

use Win32::OLE qw(in);
use Win32::OLE::Const;
use Win32::OLE::Variant;
Expand All @@ -18,6 +15,9 @@

$Win32::OLE::Warn = 2; # die on errors...

use Path::Tiny;
use Set::Scalar;

#----------------------------------------------------------#
# GetOpt section
#----------------------------------------------------------#
Expand All @@ -30,7 +30,7 @@ =head1 SYNOPSIS

GetOptions(
'help|?' => sub { HelpMessage(0) },
'i|input=s' => \( my $file_yaml = 'Fig.S1.yaml' ),
'input|i=s' => \( my $file_yaml = 'Fig.S1.yaml' ),
) or HelpMessage(1);

#----------------------------------------------------------#
Expand All @@ -45,8 +45,8 @@ =head1 SYNOPSIS

# Excel files should be located in the same dir as the yaml file.
# new excel table file will be named after yaml file.
$file_yaml = file($file_yaml)->absolute;
my $base_dir = $file_yaml->dir->stringify;
$file_yaml = path($file_yaml)->absolute;
my $base_dir = $file_yaml->parent->stringify;
my $newfile = $file_yaml->stringify;
$newfile =~ s/\.ya?ml$/.xlsx/;
unlink $newfile if -e $newfile;
Expand Down Expand Up @@ -80,7 +80,7 @@ =head1 SYNOPSIS
printf "[file: %s]\n", $filename;

# open xls file
my $efile = file( $base_dir, $filename )->stringify;
my $efile = path( $base_dir, $filename )->stringify;
if ( !-e $efile ) {
warn "File not exists: $efile\n";
next;
Expand Down
25 changes: 10 additions & 15 deletions print_xlsx.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use warnings;
use autodie;

use Getopt::Long;
use Pod::Usage;
use Getopt::Long qw(HelpMessage);
use FindBin;
use YAML qw(Dump Load DumpFile LoadFile);

use Win32::OLE qw(in with);
Expand All @@ -13,27 +13,22 @@
use Win32::OLE::NLS qw(:LOCALE :DATE);
use Win32::OLE::Const 'Microsoft Excel';

use Path::Class;

$Win32::OLE::Warn = 2; # die on errors...

#----------------------------------------------------------#
# GetOpt section
#----------------------------------------------------------#
# running options
my $file_xlsx = 'Fig.S1.yaml';

my $man = 0;
my $help = 0;
=head1 SYNOPSIS
GetOptions(
'help|?' => \$help,
'man' => \$man,
'i|input=s' => \$file_xlsx,
) or pod2usage(2);
perl print_xlsx.pl -i 1.xlsx
pod2usage(1) if $help;
pod2usage( -exitstatus => 0, -verbose => 2 ) if $man;
=cut

GetOptions(
'help|?' => sub { HelpMessage(0) },
'input|i=s' => \my $file_xlsx,
) or HelpMessage(1);

#----------------------------------------------------------#
# init
Expand Down
2 changes: 1 addition & 1 deletion xlsx2csv.pl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ =head1 SYNOPSIS
GetOptions(
'help|?' => sub { HelpMessage(0) },
'file|f=s' => \( my $file_excel ),
'sheet=s' => \my $sheetname,
'sheet=s' => \( my $sheetname ),
) or HelpMessage(1);

if ( !defined $file_excel ) {
Expand Down
13 changes: 0 additions & 13 deletions xlsx2xls.vbs

This file was deleted.

0 comments on commit 057a9ad

Please sign in to comment.