本文介绍了我可以不计算各自的宽度上的Open XML SDK生成的表格设置自动调宽?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Open XML SDK从大量数据集创建Excel文件。我终于设法得到一个功能Columns节点,它指定实际将在文件中使用的所有列。有一个BestFit属性可以设置为true,但这显然不做任何事情。有没有办法自动设置这些列为最适合,以便当有人打开此文件,他们已经大小正确的金额?或者我被迫计算每个列应该提前多大的宽度,并在代码中设置?

I'm working on creating an Excel file from a large set of data by using the Open XML SDK. I've finally managed to get a functional Columns node, which specifies all of the columns which will actually be used in the file. There is a "BestFit" property that can be set to true, but this apparently does not do anything. Is there a way to automatically set these columns to "best fit", so that when someone opens this file, they're already sized to the correct amount? Or am I forced to calculate how wide each column should be in advance, and set this in the code?

推荐答案

我理解规范的方式和, BestFit 告诉您width是在Excel中自动计算的,但它不会告诉Excel它应该在下次打开时再次计算。

The way I understand the spec and this MSDN discussion, BestFit tells you the width was auto-calculated in Excel, but it does not tell Excel that it should calculate it again next time it is opened.

由于goodol我认为宽度只能在显示列时计算,因为它取决于内容,使用的字体,其他样式参数...所以即使你想自己预先计算宽度,请注意,这只是一个估计,如果内容包含大量宽字符,它可能是错误的。或者Open XML SDK是否为您执行此操作?

As "goodol" indicates in that discussion, I think the width can only be calculated when you display the column, since it depends on the contents, the font used, other style parameters... So even if you want to pre-calculate the width yourself, be aware that this is only an estimation, and it can be wrong if the contents contain lots of "wide" characters. Or does the Open XML SDK do this for you?

这篇关于我可以不计算各自的宽度上的Open XML SDK生成的表格设置自动调宽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:26