-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30b213e
commit 7156104
Showing
8 changed files
with
964 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const words = [ | ||
["10000", "10,000"], | ||
["CAP", "Capacity"], | ||
["EXCU", "Execution"], | ||
["GB", "Gigabyte"], | ||
["HR", "Hour"], | ||
["HSTD", "Hosted"], | ||
["INST", "Instance"], | ||
["M", "Million"], | ||
["MNTR", "Monitored"], | ||
["MO", "Month"], | ||
["PR", "Per"], | ||
["PROCESS", "Processed"], | ||
["PRTN", "Partition"], | ||
["RSRC", "Resources"], | ||
["TB", "Terabyte"], | ||
["TX", "Transfer"], | ||
["UN", "Unit"], | ||
["UN", "Units"], | ||
["WKSP", "Workspace"], | ||
]; | ||
|
||
const replace = (word: string): string[] => { | ||
const terms = words.filter((r) => r[0] === word.toUpperCase()); | ||
return terms.length ? terms.map((t) => t[1]) : [word]; | ||
}; | ||
|
||
export const cleanName = (name: string, uom: string) => { | ||
const abbrevs = uom.split(" "); | ||
for (let i = abbrevs.length - 1; i >= 0; i--) { | ||
const searchterms = replace(abbrevs[i]); | ||
for (const term of searchterms) { | ||
name = name.replace(new RegExp(` +${term}$`, "i"), ""); | ||
} | ||
name = name.replace(new RegExp(` +${abbrevs[i]}$`, "i"), ""); | ||
const lastword = / +([a-z]+)$/i.exec(name); | ||
if (i !== 0 && lastword && lastword.length === 2) { | ||
name = name.replace(new RegExp(` +${lastword[1]}$`, "i"), ""); | ||
} | ||
} | ||
name = name.replace(/ *- *$/, ""); | ||
// console.log('name', name); | ||
return name.trim(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import type { Line } from "$lib/interfaces/index"; | ||
import Excel, { Row, Workbook, Worksheet } from "exceljs"; | ||
import { cleanName } from "$lib/utils"; | ||
|
||
const type = | ||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; | ||
|
||
const getWorkBook = async (): Promise<Workbook> => { | ||
const url = "/sizing.xlsx"; | ||
const arrayBuffer: ArrayBuffer = await (await fetch(url)).arrayBuffer(); | ||
const workbook = new Excel.Workbook(); | ||
return await workbook.xlsx.load(arrayBuffer); | ||
}; | ||
|
||
const changeWorkBook = (workbook: Workbook, lines: Line[]) => { | ||
const worksheet: Worksheet | undefined = workbook.getWorksheet("Quote"); | ||
if (worksheet) { | ||
// console.log(worksheet.getCell("I11").value); | ||
let idx = 5; | ||
for (const line of lines) { | ||
const row: Row = worksheet.getRow(idx); | ||
const formula = line.multiplier === 1 ? `G${idx}` : `$D$2*G${idx}`; | ||
row.getCell("C").value = cleanName(line.name, line.uom); | ||
row.getCell("D").value = line.part; | ||
row.getCell("E").value = line.uom; | ||
row.getCell("F").value = line.quantity; | ||
row.getCell("G").value = line.rate; | ||
row.getCell("H").value = { formula }; | ||
++idx; | ||
} | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
const downloadWorkBook = async (workbook: Workbook) => { | ||
const buffer = await workbook.xlsx.writeBuffer(); | ||
const blob = new Blob([buffer], { type }); | ||
const link = document.createElement("a"); | ||
link.href = URL.createObjectURL(blob); | ||
link.download = "formulae.xlsx"; | ||
link.click(); | ||
URL.revokeObjectURL(link.href); | ||
}; | ||
|
||
export const exportToXls = async (lines: Line[]) => { | ||
const workbook: Workbook = await getWorkBook(); | ||
const success = changeWorkBook(workbook, lines); | ||
if (success) await downloadWorkBook(workbook); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7156104
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failed to deploy: