Java 动态列单元格宽度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/300383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 12:49:02  来源:igfitidea点击:

Dynamic column cell width

javahtmljasper-reports

提问by Dónal

I have some Jasper reports which are displayed in HTML format. I would like the width of the columns in the HTML tables to automatically resize to fit the content of the widest cell (in that column), such that all the data is displayed.

我有一些以 HTML 格式显示的 Jasper 报告。我希望 HTML 表格中列的宽度自动调整大小以适应最宽单元格(在该列中)的内容,以便显示所有数据。

Currently this does not happen because the HTML generated by Jasper specifies fixed widths for the <table> and some <td> elements, e.g.

目前这不会发生,因为 Jasper 生成的 HTML 为 <table> 和一些 <td> 元素指定了固定宽度,例如

<td style="width: 20px; height: 17px;">
  <span style="font-family: Arial; font-size: 11px;">foo-bar-baz@examp</span>
</td>

I can't simply remove all these width properties (using JavaScript), because (as shown in the HTML above) any data that would be hidden when using these widths is not even returned to the client-side

我不能简单地删除所有这些宽度属性(使用 JavaScript),因为(如上面的 HTML 所示)使用这些宽度时会隐藏的任何数据甚至不会返回到客户端

Cheers, Don

干杯,唐

回答by Jamie Love

While not perfect, you could flag the field to stretch with overflow. This would at least give you all the data. In your jrxml file it would be similar to:

虽然不完美,但您可以标记该字段以扩展溢出。这至少会给你所有的数据。在您的 jrxml 文件中,它类似于:

<textField isStretchWithOverflow="true" hyperlinkType="None">
    <reportElement style="Report Sub-Title" x="0" y="84" width="802" height="20"/>
    <textElement/>
    <textFieldExpression class="java.lang.String">
        <![CDATA["For the period ...]]>
    </textFieldExpression>
</textField>

I'm afraid I don't know of any feature of Jasper reports that would allow the dynamic resizing of column widths - It is probably one of those things that makes sense for HTML but little sense for other output formats such as PDF.

恐怕我不知道 Jasper 报告的任何功能可以允许动态调整列宽的大小 - 这可能是对 HTML 有意义但对其他输出格式(如 PDF)意义不大的事情之一。

回答by Jamie Love

In iReport there is an option called "Stretch Type". Select "Relative to Band Height"

在 iReport 中有一个名为“拉伸类型”的选项。选择“相对于波段高度”

回答by Dave Jarvis

The developers made a conscious decision to not allow cell width to stretch. For columns to change their width based on the content, it must be done through programming. A helpful tool: DynamicJasper.

开发人员有意识地决定不允许单元格宽度拉伸。对于根据内容更改其宽度的列,必须通过编程来完成。一个有用的工具:DynamicJasper

DynamicJasper creates reports dynamically, defining at runtime the columns, column width (auto width), groups, variables, fonts, charts, crosstabs, sub reports (that can also be dynamic), page size and everything else that you can define at design time.

DynamicJasper 动态创建报告,在运行时定义列、列宽(自动宽度)、组、变量、字体、图表、交叉表、子报告(也可以是动态的)、页面大小以及您可以在设计时定义的所有其他内容.