1
Fork 0

parse icloud.com numbers exports

This commit is contained in:
SheetJS 2022-07-05 02:52:55 -04:00
parent ee8b37b3a6
commit ecfa614dd8
11 changed files with 371 additions and 213 deletions

View File

@ -79,6 +79,13 @@ function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
if(!safegetzipfile(zip, '[Content_Types].xml')) {
if(safegetzipfile(zip, 'index.xml.gz')) throw new Error('Unsupported NUMBERS 08 file');
if(safegetzipfile(zip, 'index.xml')) throw new Error('Unsupported NUMBERS 09 file');
var index_zip = CFB.find(zip, 'Index.zip');
if(index_zip) {
opts = dup(opts);
delete opts.type;
if(typeof index_zip.content == "string") opts.type = "binary";
return readSync(index_zip.content, opts);
}
throw new Error('Unsupported ZIP file');
}

View File

@ -2320,6 +2320,11 @@ describe('numbers', function() {
assert.equal(get_cell(ws2, "A1").v, 1);
assert.equal(get_cell(ws2, "ALL2").v, 2);
});
it('should support icloud.com files', function() {
var wb = X.read(fs.readFileSync(dir + 'Attendance.numbers'), {type:TYPE, WTF:true});
var ws = wb.Sheets["Attendance"];
assert.equal(get_cell(ws, "A1").v, "Date");
});
});
describe('dbf', function() {
@ -2679,7 +2684,7 @@ describe('corner cases', function() {
var wb = X.read(fs.readFileSync(w), {type:TYPE});
var ws = wb.Sheets[wb.SheetNames[0]];
var B1 = get_cell(ws, "B1"), B2 = get_cell(ws, "B2");
var lio = w.match(/\.[^\.]*$/).index, stem = w.slice(0, lio).toLowerCase(), ext = w.slice(lio + 1).toLowerCase()
var lio = w.match(/\.[^\.]*$/).index, stem = w.slice(0, lio).toLowerCase(), ext = w.slice(lio + 1).toLowerCase();
switch(ext) {
case 'fm3': break;

32
test.mjs generated
View File

@ -1793,6 +1793,33 @@ describe('roundtrip features', function() {
}
}); });
it('should preserve date system', function() {[
"biff5", "ods", "slk", "xls", "xlsb", "xlsx", "xml"
].forEach(function(ext) {
// TODO: check actual date codes and actual date values
var wb0 = X.read(fs.readFileSync("./test_files/1904/1900." + ext), {type: TYPE});
assert.ok(!wb0.Workbook || !wb0.Workbook.WBProps || !wb0.Workbook.WBProps.date1904);
var wb1 = X.read(X.write(wb0, {type: TYPE, bookType: ext}), {type: TYPE});
assert.ok(!wb1.Workbook || !wb1.Workbook.WBProps || !wb1.Workbook.WBProps.date1904);
var wb2 = X.utils.book_new(); X.utils.book_append_sheet(wb2, X.utils.aoa_to_sheet([[1]]), "Sheet1");
wb2.Workbook = { WBProps: { date1904: false } };
assert.ok(!wb2.Workbook || !wb2.Workbook.WBProps || !wb2.Workbook.WBProps.date1904);
var wb3 = X.read(X.write(wb2, {type: TYPE, bookType: ext}), {type: TYPE});
assert.ok(!wb3.Workbook || !wb3.Workbook.WBProps || !wb3.Workbook.WBProps.date1904);
var wb4 = X.read(fs.readFileSync("./test_files/1904/1904." + ext), {type: TYPE});
assert.ok(wb4.Workbook.WBProps.date1904);
var wb5 = X.read(X.write(wb4, {type: TYPE, bookType: ext}), {type: TYPE});
assert.ok(wb5.Workbook.WBProps.date1904); // xlsb, xml
var wb6 = X.utils.book_new(); X.utils.book_append_sheet(wb6, X.utils.aoa_to_sheet([[1]]), "Sheet1");
wb6.Workbook = { WBProps: { date1904: true } };
assert.ok(wb6.Workbook.WBProps.date1904);
var wb7 = X.read(X.write(wb6, {type: TYPE, bookType: ext}), {type: TYPE});
assert.ok(wb7.Workbook.WBProps.date1904);
}); });
});
//function password_file(x){return x.match(/^password.*\.xls$/); }
@ -2280,6 +2307,11 @@ describe('numbers', function() {
assert.equal(get_cell(ws2, "A1").v, 1);
assert.equal(get_cell(ws2, "ALL2").v, 2);
});
it('should support icloud.com files', function() {
var wb = X.read(fs.readFileSync(dir + 'Attendance.numbers'), {type:TYPE, WTF:true});
var ws = wb.Sheets["Attendance"];
assert.equal(get_cell(ws, "A1").v, "Date");
});
});
describe('dbf', function() {

View File

@ -2226,6 +2226,11 @@ Deno.test('numbers', async function(t) {
assert.equal(get_cell(ws2, "A1").v, 1);
assert.equal(get_cell(ws2, "ALL2").v, 2);
});
await t.step('should support icloud.com files', async function(t) {
var wb = X.read(fs.readFileSync(dir + 'Attendance.numbers'), {type:TYPE, WTF:true});
var ws = wb.Sheets["Attendance"];
assert.equal(get_cell(ws, "A1").v, "Date");
});
});
Deno.test('dbf', async function(t) {

@ -1 +1 @@
Subproject commit 9c45a1abb981222577b8d5a2faa6111c1e4750fa
Subproject commit 52a2a0cea17a078c9540ab5060fc08d26aac583d

480
tests/core.js generated

File diff suppressed because it is too large Load Diff

15
tests/fixtures.js generated

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,17 @@
./test_files/1904/1900.biff5
./test_files/1904/1900.ods
./test_files/1904/1900.slk
./test_files/1904/1900.xls
./test_files/1904/1900.xlsb
./test_files/1904/1900.xlsx
./test_files/1904/1900.xml
./test_files/1904/1904.biff5
./test_files/1904/1904.ods
./test_files/1904/1904.slk
./test_files/1904/1904.xls
./test_files/1904/1904.xlsb
./test_files/1904/1904.xlsx
./test_files/1904/1904.xml
./test_files/artifacts/quattro/write_.csv
./test_files/artifacts/quattro/write_.dif
./test_files/artifacts/quattro/write_.slk
@ -22,6 +36,7 @@
./test_files/artifacts/wps/write.xls
./test_files/artifacts/wps/write.xlsx
./test_files/artifacts/wps/write.xml
./test_files/Attendance.numbers
./test_files/author_snowman.xls
./test_files/author_snowman.xls5
./test_files/author_snowman.xlsb

View File

@ -24332,6 +24332,13 @@ function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
if(!safegetzipfile(zip, '[Content_Types].xml')) {
if(safegetzipfile(zip, 'index.xml.gz')) throw new Error('Unsupported NUMBERS 08 file');
if(safegetzipfile(zip, 'index.xml')) throw new Error('Unsupported NUMBERS 09 file');
var index_zip = CFB.find(zip, 'Index.zip');
if(index_zip) {
opts = dup(opts);
delete opts.type;
if(typeof index_zip.content == "string") opts.type = "binary";
return readSync(index_zip.content, opts);
}
throw new Error('Unsupported ZIP file');
}

7
xlsx.js generated
View File

@ -24222,6 +24222,13 @@ function parse_zip(zip, opts) {
if(!safegetzipfile(zip, '[Content_Types].xml')) {
if(safegetzipfile(zip, 'index.xml.gz')) throw new Error('Unsupported NUMBERS 08 file');
if(safegetzipfile(zip, 'index.xml')) throw new Error('Unsupported NUMBERS 09 file');
var index_zip = CFB.find(zip, 'Index.zip');
if(index_zip) {
opts = dup(opts);
delete opts.type;
if(typeof index_zip.content == "string") opts.type = "binary";
return readSync(index_zip.content, opts);
}
throw new Error('Unsupported ZIP file');
}

7
xlsx.mjs generated
View File

@ -24327,6 +24327,13 @@ function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
if(!safegetzipfile(zip, '[Content_Types].xml')) {
if(safegetzipfile(zip, 'index.xml.gz')) throw new Error('Unsupported NUMBERS 08 file');
if(safegetzipfile(zip, 'index.xml')) throw new Error('Unsupported NUMBERS 09 file');
var index_zip = CFB.find(zip, 'Index.zip');
if(index_zip) {
opts = dup(opts);
delete opts.type;
if(typeof index_zip.content == "string") opts.type = "binary";
return readSync(index_zip.content, opts);
}
throw new Error('Unsupported ZIP file');
}