58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
|
import office from 'apigo.cc/gojs/office'
|
||
|
import co from 'apigo.cc/gojs/console'
|
||
|
import file from 'apigo.cc/gojs/file'
|
||
|
|
||
|
// 测试 makeCellID
|
||
|
for (let x = 0; x < 1000; x++) {
|
||
|
for (let y = 0; y < 100; y++) {
|
||
|
let cellID = office.makeCellID(x, y)
|
||
|
let [x1, y1] = office.parseCellID(cellID)
|
||
|
if (x1 !== x || y1 !== y) {
|
||
|
co.error('failed', x, y, cellID, x1, y1)
|
||
|
return 'test parseCellID failed'
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
let x = office.openExcel('a.xlsx', '123456')
|
||
|
x.set(0, [['A', 'B', 'C'], ['1', '2', '3'], [1, 2, 3], [1, 2, 3]])
|
||
|
|
||
|
let d = x.get(0, 'A2')
|
||
|
if (d[0][1] !== '2') {
|
||
|
co.error('test get failed', d)
|
||
|
return 'test get failed'
|
||
|
}
|
||
|
if (d[1][1] !== 2) {
|
||
|
co.error('test get failed', d)
|
||
|
return 'test get failed'
|
||
|
}
|
||
|
|
||
|
x.setData(0, [{ '1': 4, '2': 5, '3': 6 }, { '1': 'A', '2': 'B', '3': 'C' }], 'A2', 'B3')
|
||
|
x.save()
|
||
|
|
||
|
try {
|
||
|
office.openExcel('a.xlsx', '12345')
|
||
|
return 'test openExcel with bad password failed'
|
||
|
} catch {
|
||
|
}
|
||
|
|
||
|
let x1 = office.openExcel('a.xlsx', '123456')
|
||
|
d = x1.getData(0, 'A2', 'C4')
|
||
|
if (d[0]['1'] !== 4) {
|
||
|
co.error('test getData failed', d)
|
||
|
return 'test getData failed'
|
||
|
}
|
||
|
if (d[0]['3'] !== 3) {
|
||
|
co.error('test getData failed', d)
|
||
|
return 'test getData failed'
|
||
|
}
|
||
|
if (d[1]['2'] !== 2) {
|
||
|
co.error('test getData failed', d)
|
||
|
return 'test getData failed'
|
||
|
}
|
||
|
|
||
|
|
||
|
file.remove('a.xlsx')
|
||
|
|
||
|
return true
|