Excel 将分组头信息填入组内明细行

Excel由多个纵向的分组表组成,组之间由空白行隔开,每组第1、2行的第2格是分组表头,第3行是列头,第1列和第6列数据是空白的:

|----|--------|-----------------|------|------|------------|----------|
| | A | B | C | D | E | F |
| 1 | | ATLANTIC SPIRIT | | | | |
| 2 | | Looe | | | | |
| 3 | Vessel | Species | Size | Kg | Date | Location |
| 4 | | POLLACK | 2 | 2.5 | 23/04/2024 | |
| 5 | | POLLACK | 3 | 18.8 | 23/04/2024 | |
| 6 | | POLLACK | 41 | 5.4 | 23/04/2024 | |
| 7 | | LING | 3 | 1.9 | 23/04/2024 | |
| 8 | | WHITING | 2 | 0.4 | 23/04/2024 | |
| 9 | | | | | | |
| 10 | | BEADY EYE | | | | |
| 11 | | Plymouth | | | | |
| 12 | Vessel | Species | Size | Kg | Date | Location |
| 13 | | BASS | 4 | 15.7 | 23/04/2024 | |
| 14 | | BASS | 5 | 3.2 | 23/04/2024 | |
| 15 | | | | | | |
| 16 | | BOY JACK | | | | |
| 17 | | Plymouth | | | | |
| 18 | Vessel | Species | Size | Kg | Date | Location |
| 19 | | PLAICE | 1 | 0.8 | 23/04/2024 | |
| 20 | | BLONDE RAY | 1 | 14.3 | 23/04/2024 | |
| 21 | | BLONDE RAY | 3 | 1.6 | 23/04/2024 | |
| 22 | | SPOTTED RAY | 5 | 1.2 | 23/04/2024 | |
| 23 | | THORNBACK RAY | 1 | 6.3 | 23/04/2024 | |
| 24 | | THORNBACK RAY | 2 | 15.7 | 23/04/2024 | |
| 25 | | THORNBACK RAY | 3 | 10.9 | 23/04/2024 | |
| 26 | | THORNBACK RAY | 4 | 2.6 | 23/04/2024 | |
| 27 | | LOBSTER | 1 | 2.7 | 23/04/2024 | |
| 28 | | LOBSTER | 2 | 1.1 | 23/04/2024 | |
| 29 | | RAY BACKS | 1 | 42.1 | 23/04/2024 | |

需要把每组第1、2行的分组表头填入第1列和第6列:

|----|-----------------|-----------------|------|------|------------|----------|
| | A | B | C | D | E | F |
| 1 | | ATLANTIC SPIRIT | | | | |
| 2 | | Looe | | | | |
| 3 | Vessel | Species | Size | Kg | Date | Location |
| 4 | ATLANTIC SPIRIT | POLLACK | 2 | 2.5 | 23/04/2024 | Looe |
| 5 | ATLANTIC SPIRIT | POLLACK | 3 | 18.8 | 23/04/2024 | Looe |
| 6 | ATLANTIC SPIRIT | POLLACK | 41 | 5.4 | 23/04/2024 | Looe |
| 7 | ATLANTIC SPIRIT | LING | 3 | 1.9 | 23/04/2024 | Looe |
| 8 | ATLANTIC SPIRIT | WHITING | 2 | 0.4 | 23/04/2024 | Looe |
| 9 | | | | | | |
| 10 | | BEADY EYE | | | | |
| 11 | | Plymouth | | | | |
| 12 | Vessel | Species | Size | Kg | Date | Location |
| 13 | BEADY EYE | BASS | 4 | 15.7 | 23/04/2024 | Plymouth |
| 14 | BEADY EYE | BASS | 5 | 3.2 | 23/04/2024 | Plymouth |
| 15 | | | | | | |
| 16 | | BOY JACK | | | | |
| 17 | | Plymouth | | | | |
| 18 | Vessel | Species | Size | Kg | Date | Location |
| 19 | BOY JACK | PLAICE | 1 | 0.8 | 23/04/2024 | Plymouth |
| 20 | BOY JACK | BLONDE RAY | 1 | 14.3 | 23/04/2024 | Plymouth |
| 21 | BOY JACK | BLONDE RAY | 3 | 1.6 | 23/04/2024 | Plymouth |
| 22 | BOY JACK | SPOTTED RAY | 5 | 1.2 | 23/04/2024 | Plymouth |
| 23 | BOY JACK | THORNBACK RAY | 1 | 6.3 | 23/04/2024 | Plymouth |
| 24 | BOY JACK | THORNBACK RAY | 2 | 15.7 | 23/04/2024 | Plymouth |
| 25 | BOY JACK | THORNBACK RAY | 3 | 10.9 | 23/04/2024 | Plymouth |
| 26 | BOY JACK | THORNBACK RAY | 4 | 2.6 | 23/04/2024 | Plymouth |
| 27 | BOY JACK | LOBSTER | 1 | 2.7 | 23/04/2024 | Plymouth |
| 28 | BOY JACK | LOBSTER | 2 | 1.1 | 23/04/2024 | Plymouth |
| 29 | BOY JACK | RAY BACKS | 1 | 42.1 | 23/04/2024 | Plymouth |

使用 SPL XLL,输入公式:

复制代码
=spl("=t=?.group@i(!~.ifn()),k=1,t.run(t1=~(k)(2),t6=~(k+1)(2),~.m(k+3:).run(~(1)=t1,~(6)=t6),k=2),t.conj()",A1:F29)

函数 group@i 按条件进行分组,ifn()返回第 1 个非空成员,~ 是当前成员,~(6) 是当前成员的第 6 个下级成员,m(k+1:) 是第 k+1 个到最后一个成员。

相关推荐
Python大数据分析@6 分钟前
python操作CSV和excel,如何来做?
开发语言·python·excel
John.liu_Test41 分钟前
js下载excel示例demo
前端·javascript·excel
ruleslol3 小时前
VBA02-初识宏——EXCEL录像机
excel·vba
IT铺子3 小时前
制定Excel使用规范和指导,提升数据处理的效率和准确性,减少错误和数据丢失的风险
excel
是萝卜干呀3 小时前
Backend - Python 爬取网页数据并保存在Excel文件中
python·excel·table·xlwt·爬取网页数据
神奇夜光杯9 小时前
Python酷库之旅-第三方库Pandas(202)
开发语言·人工智能·python·excel·pandas·标准库及第三方库·学习与成长
小c君tt10 小时前
MFC中Excel的导入以及使用步骤
c++·excel·mfc
一名技术极客12 小时前
Vue2 doc、excel、pdf、ppt、txt、图片以及视频等在线预览
pdf·powerpoint·excel·文件在线预览
用余生去守护12 小时前
【反射率】-- Lab 转换(excel)
excel
进击的六角龙12 小时前
Python中处理Excel的基本概念(如工作簿、工作表等)
开发语言·python·excel