BEGIN { $| = 1;
print
"1..4\n"
; }
END {
print
"not ok 1\n"
unless
$loaded
;}
use
Data::Table::Excel
qw(tables2xls xls2tables tables2xlsx xlsx2tables is_xlsx xls2xlsx xlsx2xls excelFileToTable)
;
$loaded
= 1;
print
"ok loaded\n"
;
my
$t_category
= Data::Table::fromFile(
"Category.csv"
);
my
$t_product
= Data::Table::fromFile(
"Product.csv"
);
if
(-e
'NorthWind.xls'
) {
unlink
(
"NorthWind.xls"
) }
tables2xls(
"NorthWind.xls"
, [
$t_category
,
$t_product
], [
"Category"
,
"Product"
]);
if
(-e
'NorthWind.xls'
) {
print
"ok 1 table2xls\n"
;
}
else
{
print
"not ok 1 table2xls\n"
;
}
my
(
$tableObjects
,
$tableNames
)=xls2tables(
"NorthWind.xls"
);
if
(
scalar
@$tableObjects
!=2 ||
scalar
@$tableNames
!=2) {
print
"not ok 2 xls2tables\n"
;
}
else
{
if
(
$tableNames
->[0] eq
'Category'
&&
$tableNames
->[1] eq
'Product'
&&
$tableObjects
->[0]->nofRow==
$t_category
->nofRow &&
$tableObjects
->[1]->nofRow==
$t_product
->nofRow &&
$tableObjects
->[0]->nofCol==
$t_category
->nofCol &&
$tableObjects
->[1]->nofCol==
$t_product
->nofCol) {
print
"ok 2 xls2tables\n"
;
}
else
{
print
"not ok 2 xls2tables\n"
;
}
}
if
(-e
'NorthWind.xlsx'
) {
unlink
(
"NorthWind.xlsx"
) }
tables2xlsx(
"NorthWind.xlsx"
, [
$t_category
,
$t_product
],
undef
, [[
'silver'
,
'white'
,
'black'
], [45,
'white'
,37]]);
if
(-e
'NorthWind.xlsx'
) {
print
"ok 3 table2xlsx\n"
;
}
else
{
print
"not ok 3 table2xlsx\n"
;
}
my
(
$tableObjects
,
$tableNames
)=xlsx2tables(
"NorthWind.xlsx"
);
if
(
scalar
@$tableObjects
!=2 ||
scalar
@$tableNames
!=2) {
print
"not ok 4 xlsx2tables\n"
;
}
else
{
if
(
$tableNames
->[0] eq
'Sheet1'
&&
$tableNames
->[1] eq
'Sheet2'
&&
$tableObjects
->[0]->nofRow==
$t_category
->nofRow &&
$tableObjects
->[1]->nofRow==
$t_product
->nofRow &&
$tableObjects
->[0]->nofCol==
$t_category
->nofCol &&
$tableObjects
->[1]->nofCol==
$t_product
->nofCol) {
print
"ok 4 xlsx2tables\n"
;
}
else
{
print
"not ok 4 xlsx2tables\n"
;
}
}
if
(is_xlsx(
'NorthWind.xlsx'
) and !is_xlsx(
'NorthWind.xls'
)) {
print
"ok 5 is_xlsx\n"
;
}
else
{
print
"not ok 5 is_xlsx\n"
;
}
my
(
$tableObjects2
) = excelFileToTable(
"NorthWind.xlsx"
);
if
(
$tableObjects
->[0]->nofRow==
$tableObjects2
->[0]->nofRow &&
$tableObjects
->[1]->nofRow==
$tableObjects2
->[1]->nofRow &&
$tableObjects
->[0]->nofCol==
$tableObjects2
->[0]->nofCol &&
$tableObjects
->[1]->nofCol==
$tableObjects2
->[1]->nofCol) {
print
"ok 6 excelFileToTable\n"
;
}
else
{
print
"not ok 6 excelFileToTable\n"
;
}
xls2xlsx(
'NorthWind.xls'
,
't.xlsx'
);
my
(
$tableObjects2
) = xlsx2tables(
"t.xlsx"
);
if
(
$tableObjects
->[0]->nofRow==
$tableObjects2
->[0]->nofRow &&
$tableObjects
->[1]->nofRow==
$tableObjects2
->[1]->nofRow &&
$tableObjects
->[0]->nofCol==
$tableObjects2
->[0]->nofCol &&
$tableObjects
->[1]->nofCol==
$tableObjects2
->[1]->nofCol) {
print
"ok 7 xls2xlsx\n"
;
}
else
{
print
"not ok 7 xlsx2xls\n"
;
}
if
(-e
't.xlsx'
) {
unlink
(
"t.xlsx"
) }
xlsx2xls(
'NorthWind.xlsx'
,
't.xls'
);
my
(
$tableObjects2
) = xls2tables(
"t.xls"
);
if
(
$tableObjects
->[0]->nofRow==
$tableObjects2
->[0]->nofRow &&
$tableObjects
->[1]->nofRow==
$tableObjects2
->[1]->nofRow &&
$tableObjects
->[0]->nofCol==
$tableObjects2
->[0]->nofCol &&
$tableObjects
->[1]->nofCol==
$tableObjects2
->[1]->nofCol) {
print
"ok 8 xlsx2xls\n"
;
}
else
{
print
"not ok 8 xlsx2xls\n"
;
}
if
(-e
't.xls'
) {
unlink
(
"t.xls"
) }
1;