|
vba数组很难操作,有JS写更方便点,用WPS Office 2022打开使用
- function test_data()
- {
- const data = [];
- for (let sht of [Sheets('一层'), Sheets('二层')])
- {
- let c1 = sht.Range('B5:B15').Value2
- , c2 = sht.Range('H5:H15').Value2
- , c3 = sht.Range('M5:M15').Value2
- , arr = [['第' + sht.Name]].concat(c1, c2, c3);
- //完成层数
- arrdim(data, arr);
- //完成厨房间
- c1 = sht.Range('C19:C29').Value2;
- c1.unshift([sht.Range('B18').Value2]);
- arrdim(data, c1);
- //完成卫生间1
- c1 = sht.Range('H19:H29').Value2;
- c1.unshift([sht.Range('G18').Value2]);
- arrdim(data, c1);
- //完成卫生间2
- c1 = sht.Range('M19:M29').Value2;
- c1.unshift([sht.Range('L18').Value2]);
- arrdim(data, c1);
- };
- let page = Math.ceil(data.length / 28); //分页取整,若有余数+1
- for (let i = 1; i <= page; i++)
- {
- let sht = Sheets('装修' + i);
- if (i < page) {
- let arr = data.slice(i * 28 - 28, i * 28).map(i => [i]);
- sht.Range('C5:C32').Value2 = arr
- } else {
- let arr = data.slice(i * 28 - 28).map(i => [i]);
- sht.Range('C5').Resize(arr.length, 1).Value2 = arr
- }
- }
-
- alert('完成')
- }
- function arrdim(data, arr)
- {
- let res = [];
- arr.forEach(i => i[0] ? res.push(i[0]) : '');
- let req = Array.from(new Set(res));
- req.forEach(i => data.push(i));
- data.push('', '')
-
- }
复制代码 |
|