通过 JXL 添加到 Excel 时图像变得模糊
我使用 JXL API 将图像添加到 Excel 文件。使用的库:
jcommon (1.0.14)
jfreechart (1.0.13)
jxl (2.6.10)
// chartImage is of type BufferedImage
com.KeyPoint.PngEncoder encoder = new com.KeyPoint.PngEncoder(chartImage, true, 0, 0);
jxl.write.WritableImage image = new jxl.write.WritableImage(0, 2, (chartImage.getWidth()/100),16,
encoder.pngEncode());
sheet.addImage(image);
问题在于 WritableImage 构造函数采用行和列的宽度和高度(宽度:第 0 列到列 ChartImage.getWidth()/100,高度:第 2 行到第 16 行)。这会导致图表图像模糊。
如何使用 JXL 将原始图像导入 Excel?请帮忙。谢谢! :-)
I use the JXL API to add an Image to an Excel file. Libraries used:
jcommon (1.0.14)
jfreechart (1.0.13)
jxl (2.6.10)
// chartImage is of type BufferedImage
com.KeyPoint.PngEncoder encoder = new com.KeyPoint.PngEncoder(chartImage, true, 0, 0);
jxl.write.WritableImage image = new jxl.write.WritableImage(0, 2, (chartImage.getWidth()/100),16,
encoder.pngEncode());
sheet.addImage(image);
The problem is that the WritableImage constructors take widths and heights in terms of rows and columns (width: column 0 to column chartImage.getWidth()/100, height: row 2 to row 16). This causes the chart image to blur.
How do I get the original image into the Excel using JXL? Kindly help. Thanks! :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题在于 Excel 中使用的压缩或您使用的编码器。
一种有效的解决方案是将图表绘制得比预期图像大,然后让 Excel 进行缩小。尽管充满图表的工作簿将比以前大得多,但这可以确保清晰度。
AFAIK 这是解决问题的唯一方法。我在使用 Word 和 PowerPoint 时也遇到过类似的问题,解决方案似乎是升级。
当您缩放图表时,您应该注意字体大小也需要更改。
The issue lies with either the compression used in Excel or the encoder you used.
A solution that works is drawing the chart larger than the intended image, and then letting Excel do the down-scaling. This ensures clarity although a chart-filled workbook will be much larger than before.
AFAIK that is the only solution to the problem. I have had similar issues with Word and PowerPoint, and the solution seems to be upscaling.
When you scale the chart you should note that the font sizes need to be changed too.
不要直接使用
PngEncoder
。相反,请使用相关的ChartUtilities
方法,它将查找 Sun/Oracle PNG 编码器(如果可用)。Don't use
PngEncoder
directly. Instead, use the relevantChartUtilities
method, which will find the Sun/Oracle PNG encoder if available.