简体   繁体   English

如何在 perl 中获取合并的 Excel 单元格的大小?

[英]How do I get the size of a merged Excel cell in perl?

I'm trying to implement code in Perl to parse a large Excel sheet as the below Excel example:我正在尝试在 Perl 中实现代码来解析大型 Excel 工作表,如下面的 Excel 示例:

我的 Excel 示例图像

For example, in the attached image you can see that 3 elements are assigned as named "rsvd" "frame_kind" and "destination" .例如,在附加图像中,您可以看到 3 个元素被指定为名为"rsvd" "frame_kind""destination"

So I want to make a data structure with the size of a merged excel cell in Perl.所以我想在 Perl 中创建一个合并的 excel 单元格大小的数据结构。

eg) what I want to get the information is that rsvd has merged from 16 to 31 and the size of rsvd 16.例如)我想要得到的信息是rsvd已从 16 合并到 31 并且rsvd的大小为 16。

frame_kind has merged from 14 to 15 and the size of frame_kind 2. frame_kind已从 14 合并到 15, frame_kind的大小为 2。

destination has merged from 0 to 13 and the size of destination 14. destination已从 0 合并到 13, destination的大小为 14。

How can I get the location of a cell a certain merged number of cells away and size in Perl?如何在 Perl 中获取某个合并单元格数量和大小的单元格的位置?

The Spreadsheet::ParseExcel module has a get_cell method which returns a Cell object. Spreadsheet::ParseExcel模块有一个get_cell方法,它返回一个Cell对象。 The Cell object does not look like it directly tells how big it is, but you can use the value and is_merged methods to determine the size of the merged cells. Cell 对象看起来并不直接告诉它有多大,但是可以使用valueis_merged方法来确定合并单元格的大小。

Start at the expected cell ( C6 in your example), then loop through the columns in Row 6, checking the value and whether the cell is merged.从预期的单元格(在您的示例中为C6 )开始,然后遍历第 6 行中的列,检查值以及单元格是否已合并。 The value will start at rsvd , and once the value is not rsvd , you know you found the end of the 1st merged cell.该值将从rsvd开始,一旦该值不是rsvd ,您就知道您找到了第一个合并单元格的结尾。 Repeat this loop for the remaining columns in the row to get all merged cells.对行中的其余列重复此循环以获取所有合并的单元格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM