| 52 | } |
| 53 | |
| 54 | addWorksheet(name, options) { |
| 55 | const id = this.nextId; |
| 56 | |
| 57 | // if options is a color, call it tabColor (and signal deprecated message) |
| 58 | if (options) { |
| 59 | if (typeof options === 'string') { |
| 60 | // eslint-disable-next-line no-console |
| 61 | console.trace( |
| 62 | 'tabColor argument is now deprecated. Please use workbook.addWorksheet(name, {properties: { tabColor: { argb: "rbg value" } }' |
| 63 | ); |
| 64 | options = { |
| 65 | properties: { |
| 66 | tabColor: {argb: options}, |
| 67 | }, |
| 68 | }; |
| 69 | } else if (options.argb || options.theme || options.indexed) { |
| 70 | // eslint-disable-next-line no-console |
| 71 | console.trace( |
| 72 | 'tabColor argument is now deprecated. Please use workbook.addWorksheet(name, {properties: { tabColor: { ... } }' |
| 73 | ); |
| 74 | options = { |
| 75 | properties: { |
| 76 | tabColor: options, |
| 77 | }, |
| 78 | }; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | const lastOrderNo = this._worksheets.reduce((acc, ws) => ((ws && ws.orderNo) > acc ? ws.orderNo : acc), 0); |
| 83 | const worksheetOptions = Object.assign({}, options, { |
| 84 | id, |
| 85 | name, |
| 86 | orderNo: lastOrderNo + 1, |
| 87 | workbook: this, |
| 88 | }); |
| 89 | |
| 90 | const worksheet = new Worksheet(worksheetOptions); |
| 91 | |
| 92 | this._worksheets[id] = worksheet; |
| 93 | return worksheet; |
| 94 | } |
| 95 | |
| 96 | removeWorksheetEx(worksheet) { |
| 97 | delete this._worksheets[worksheet.id]; |