diff --git a/test/crud-test.ts b/test/crud-test.ts index fefa045..a4035ec 100644 --- a/test/crud-test.ts +++ b/test/crud-test.ts @@ -1224,6 +1224,41 @@ describe("CRUD operations", function() { }); }); + it("Insert imageincells and create rels", function(done) { + fs.readFile(path.join(__dirname, 'templates', 'test-insert-images_in_cell.xlsx'), function(err, data) { + expect(err).toBeNull(); + var option = { + imageRootPath : path.join(__dirname, 'templates', 'dataset') + } + var t = new XlsxTemplate(data, option); + var imgB64 = 'iVBORw0KGgoAAAANSUhEUgAAALAAAAA2CAYAAABnXhObAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsIAAA7CARUoSoAAAAUjSURBVHhe7ZtbyGVjGMfXlmmccpqRcYgZmQsTMeVYQiJzozEYJRHCcCUaNy5kyg3KhUNEhjSRbwipIcoF0pRpxiFiLsYUIqcoZ8b2/6/1vKtnv3u9+/smuXjW/v/qv593PetZa+/17f9617vetb9BVVVDSIiQ7GFRiJC0PfBwOGRbiBAMBoPat+qBRWhkYBEaGViERgYWoZGBRWhkYBEaGViERgYWoZGBRWhkYBEaGViERgYWoZGBRWhkYBEaGViERgYWoenND9oHg8EFCOdBPJ57cDzfWf5MhLPZBr9AL2LdzmZxFNTui3AdtF+dqKqtqH3F2iOg9g6EVLcFdTPW7gT1CxAuhE6FFkG/Ql9Cm7HtC4gtqL0S4ehmaRzU32XNiWA/VyGcDGGT4c11sifg2Np/hWODB8iXsAJ3p2OBznL5rS5Pfey38wJPuzpqe6HuXFdDfdRVlwRo9r+stkvboYWu/ifLlzTP7z8XOBZ63mqTDuyqjap0XNMwhGCvStjjkeNw9q6ydgtyCxEub5Za5lnMWW0xsQzbn2btEZBfh0DtWSeq6h3oQeghaBMTYCl0UtMc4U/obegN6FXoJWgGXyBPhk7wfrcgfAJdXCemgNrJ3t0RBUo98KeW+wCiIdjmMCLfnpdYNrw+y+us9ltb/6FFisOWvO4Ut/4HaHWh5j7odJdLPfAXvnYuAk/Ztuuhn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ute('init_rels', { + imgB64 : imgB64, + }); + var newData = t.generate(); + var richDataFile = etree.parse(t.archive.file("xl/richData/_rels/richValueRel.xml.rels").asText()).getroot(); + expect(richDataFile.findall("Relationship").length).toEqual(4); + var richDataFile = etree.parse(t.archive.file("xl/richData/rdrichvalue.xml").asText()).getroot(); + expect(richDataFile.findall("rv").length).toEqual(4); + expect(parseInt(richDataFile.attrib.count)).toEqual(richDataFile.findall("rv").length); + var richDataFile = etree.parse(t.archive.file("xl/richData/richValueRel.xml").asText()).getroot(); + expect(richDataFile.findall("rel").length).toEqual(4); + var richDataFile = etree.parse(t.archive.file("xl/metadata.xml").asText()).getroot(); + expect(parseInt(richDataFile.find('futureMetadata').attrib.count)).toEqual(4); + expect(parseInt(richDataFile.find('valueMetadata').attrib.count)).toEqual(4); + expect(richDataFile.find('futureMetadata').findall("bk").length).toEqual(4); + expect(richDataFile.find('valueMetadata').findall("bk").length).toEqual(4); + var sheet1 = etree.parse(t.archive.file("xl/worksheets/sheet1.xml").asText()).getroot(); + expect(sheet1.find("./sheetData/row[@r='3']/c[@r='B3']").attrib.vm).toEqual("1"); + expect(sheet1.find("./sheetData/row[@r='5']/c[@r='K5']").attrib.vm).toEqual("2"); + expect(sheet1.find("./sheetData/row[@r='6']/c[@r='D6']").attrib.vm).toEqual("3"); + expect(sheet1.find("./sheetData/row[@r='10']/c[@r='H10']").attrib.vm).toEqual("4"); + fs.writeFileSync('test/output/insert_imageincell.xlsx', newData, 'binary'); + done(); + }); + }); + it("Insert some format of image", function(done) { fs.readFile(path.join(__dirname, "templates", "test-insert-images.xlsx"), function(err, data) { expect(err).toBeNull();