-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathexcel.ts
59 lines (51 loc) · 2.15 KB
/
excel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
import { WorkbookRange, WorkbookWorksheet } from "@microsoft/microsoft-graph-types";
import { assert } from "chai";
import * as fs from "fs";
import { getClient, randomString } from "../test-helper";
const client = getClient();
const ExcelFilename = `empty-spreadsheet-${randomString()}.xlsx`;
describe("Excel", function() {
this.timeout(10 * 1000);
beforeEach((done) => {
setTimeout(() => {
done();
}, 1000);
});
it("Uploads an Excel file to OneDrive", async () => {
const file = fs.readFileSync("./test/sample_files/empty-spreadsheet.xlsx");
const res = await client.api(`/me/drive/root/children/${ExcelFilename}/content`).put(file);
assert.isDefined(res.id);
});
it("Lists the worksheets in an excel file", async () => {
const res = await client.api(`/me/drive/root:/${ExcelFilename}:/workbook/worksheets`).get();
const worksheets = res.value as WorkbookWorksheet[];
const sheet1 = worksheets[0];
assert.isNumber(sheet1.position);
assert.isString(sheet1.visibility);
assert.isString(sheet1.id);
assert.isUndefined(sheet1["random fake property that should be null"]);
});
it("Updates workbook worksheet range", async () => {
const sampleData: WorkbookRange = {
values: [
["cell a1", "cell a2"],
["cell b1", "cell b2"],
],
};
const response = await client.api(`/me/drive/root:/${ExcelFilename}:/workbook/worksheets/Sheet1/range(address='A1:B2')`).patch(sampleData);
assert.isDefined(response["@odata.id"]);
assert.isDefined(response.values);
});
it("GETs the used range of the worksheet", async () => {
const res: WorkbookRange = await client.api(`/me/drive/root:/${ExcelFilename}:/workbook/worksheets/Sheet1/range/usedrange`).get();
assert.isNumber(res.cellCount);
assert.isString(res.address);
assert.isUndefined(res["random fake property that should be null"]);
});
});