如何将带换行符的内容从 JTable 复制到 Excel(包含换行符)
我有一个应用程序,其中每个单元格中都有一个带有换行符(编辑时按 Enter 键)的 JTable。
当我将 JTable 中的内容复制到 Excel 时,出现问题,我没有将 Jtable(带换行符)中相同格式的内容复制到带换行符的 Excel 中。
有什么方法可以解决我的问题。我必须将 jtable 中的内容以相同的格式(带换行符)导出到 excel 中。
谢谢 柴图
I have an application where I have a JTable with line breaks(pressing Enter key while editing) included in each and every cell.
The problem appears when I copy the contents from my JTable to Excel, I am not getting the contents in same format as in my Jtable(with line breaks) to my excel that is with line breaks.
Is there any way to solve my problem.I have to get the contents from my jtable to excel in the same format with line breaks.
Thank You
Chaithu
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对DnD了解不多。我认为通常您会为每个单元格数据使用分隔符(如逗号或制表符),然后为每行数据使用换行符。
因此,如果您的单元格数据包含换行符,您可能需要将单元格数据包装在“...”中。这意味着您需要为表编写一个自定义 TransferHandler。来自 JDK5 教程可能会帮助您入门。
I don't know much about DnD. I think that typically you use a delimiter for each cell data (like comma or tab) and then a newline for each row of data.
So if your cell data contains newline characters you would probably need to wrap the cell data in "...". This would mean you need to write a custom TransferHandler for the table. The old TableTransferHandler from the JDK5 tutorial might help you get started.
你是如何复制内容的?您是否使用内置的复制支持?(即选择所有内容并使用 ctrl-c 进行复制),还是您自己编写了一些内容来进行复制和粘贴?
您可能必须执行后者,并确保在文本中插入必要的换行符。
How are you copying the contents? Are you using the build in copy support?(ie select all contents and copy w/ ctrl-c), or did you write something yourself to do the copy and paste?
You may have to do the latter, and make sure that you insert the necessary line break characters in to the text.