能自己搞定就好~
- function 生成采购计划() {
- const price = {};
- const dic = Sheets('餐谱').Cells(1).CurrentRegion().slice(1).reduce((a, [A, , , , E, F, G]) => {
- a[A] ??= [];
- a[A].push([E, F]);
- price[E] ??= G;
- return a;
- }, {});
- const res = Object.entries(Sheets('就餐日').Cells(1).CurrentRegion().slice(1).reduce((a, [A, B]) => {
- let week = WorksheetFunction.Text(A, 'aaaa');
- dic[week].forEach(([food, weight]) => {
- a[food] ??= 0;
- a[food] += B * weight / 500;
- });
- return a;
- }, {})).map(([f, n]) => [f, n, 500 * price[f], n * 500 * price[f]]);
- res.sort((a, b) => b[3] - a[3]); // 按总价排序
- res.unshift(['品名', '数量(斤)', '单价(元/斤)', '总价(元)']); // 插入表头
- with (Sheets('采购计划').Cells(1).Resize(res.length, res[0].length)) {
- CurrentRegion.Clear();
- Value2 = res;
- Borders.LineStyle = xlContinuous;
- }
- }
复制代码 |