我们如何根据 xlsx 中单元格的内容给出高度?

How can we give height based on content of a cell in xlsx?

我正在尝试通过XML创建一个Excel文件,我们如何根据单元格的内容给出高度。这里我在一行中手动添加了ht=27,有没有其他选项可以根据内容更改高度?所以3行10行也好看

<row r="26" spans="1:26" ht="27" x14ac:dyDescent="0.3">
       <c r="B26" s="3"/>
       ......
       ......
       <c r="I26" s="41" t="inlineStr">
           <is><t>long text/short text (dynamic text)</t></is>
       </c>
       ......
       ......
       <c r="Z26" s="3"/>
   </row>

任何 idea/suggestions,如何操作或替代选项

如果您要从 row 的 XML 中完全删除 htx14ac:dyDescent 属性,那么高度将根据内容自动计算,只要因为该行中没有任何合并单元格。

所以

   <row r="26" spans="1:26">
       <c r="B26" s="3"/>
       ......
       ......
       <c r="I26" s="41" t="inlineStr">
           <is><t>long text/short text (dynamic text)</t></is>
       </c>
       ......
       ......
       <c r="Z26" s="3"/>
   </row>

只要该行中没有任何合并的单元格并且 s="41" 指向 wrapText 设置为 true 的单元格样式,就应该看起来像你想要的那样。

为什么要删除 ht 的显式集应该是不言自明的。如果不存在,将进行隐式高度计算。

为什么需要额外删除 x14ac:dyDescentDocumentation of 2.5.3 dyDescent 告诉它:

The dyDescent attribute has a side effect; it sets the customHeight attribute to true even if the customHeight attribute is explicitly set to false.

所以如果设置x14ac:dyDescent,则不会进行隐式高度计算。