我可以使用java格式化要写入CSV文件的数据吗
我有一些代码将数据写入 CSV 文件,但它会将数据写入 CSV 没有正确格式化它。我想将某些特定文本加粗。这可能吗?
I have some code to write data into a CSV file, but it writes data into a CSV
without formatting it properly. I want to bold some specific text. Is that possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
CSV 只是一种纯文本格式,因此您无法进行任何格式化。
如果您想要格式化,请考虑使用 Excel 库,例如 Apache POI 或 Jasper 报告。 (当然,然后您最终会得到一个 excel 文件而不是 CSV,因此根据您的情况可能合适也可能不合适)
作为旁注,编写 CSV 有一些奇怪的细微差别(例如确保引号,逗号等已正确转义)。我使用过一个不错的轻量级库,名为 Open CSV,如果您选择坚持使用,它可能会让您的生活更轻松使用普通的旧 CSV。
CSV is just a plain text format, so you can't do any formatting.
If you want formatting, consider using an Excel library such as Apache POI or Jasper Reports. (Of course, then you end up with an excel file rather than a CSV, so depending on your situation that may or may not be appropriate)
As a side note, there are some strange nuances to writing CSV (such as making sure quotes, commas etc are properly escaped). There's a nice lightweight library I've used called Open CSV that might make your life easier if you choose to just stick with plain old CSV.
CSV是纯文本文件格式,不能使用任何文本效果。
CSV is a plain text file format, you can not use any text effect.
据我所知,CSV 是一种纯文本格式。
如果您要创建 csv,以便可以在 Excel 中打开它,那么我建议您查看 MS Excel XML 格式。
http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats#Excel_XML_Spreadsheet_example
一个示例是如下(取自维基百科链接,这使得一些文本变为粗体)
Not that I am aware of, CSV is a plain text format.
If you are creating a csv, so that you can open it up in Excel, then I would suggest taking a look at the MS Excel XML format.
http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats#Excel_XML_Spreadsheet_example
An example would be as follows (taken from the wikipedia link, and this makes some text BOLD)
我是普通的旧常规 CSV 编号。但是,您没有理由不能在写出数据之前对其进行编码...例如,粗体的 HTML 标记是 。这将向您准确表明文本的哪些部分是粗体的,并且来自众所周知的标准仍然是人类可读的。主要缺点是您必须在读取数据后对其进行解析:(
还有其他需要考虑的事情,既然您正在写出数据,为什么不以 RTF 或其他支持粗体等的格式将其写为逗号分隔值?通常CSV 是纯文本,但您没有理由不能以其他方式写出它,只需记住以相同的格式读回它即可。
I plain old regular CSV no. But there is no reason why you could not encode your data before writing it out... for example the HTML tags for bold is <b></b>. This would signal to you exactly which portions of the text are bold and being a from a well know standard is still human readable too. The main drawback is you have to parse your data after you read it :(
Something else to consider, since you are writing the data out why not write it out as comma separated values in RTF or some other format that does support bold etc? Normally CSV is plain text but there is no reason why you couldn't write it out another way. Just remember to read it back in the same format...