For a Java application that drags data together from some sources and does some calculation itself, we want to offer users the possibility to use their own format strings, and would prefer the format string syntax they know from Excel (e. g. "$ "#,###.,0
) which happens to be the same used in .net and Analysis Services.
对于将来自某些源的数据拖放到一起并自己进行计算的Java应用程序,我们希望为用户提供使用自己格式字符串的可能性,并希望使用他们从Excel中知道的格式字符串语法。“$”#、### #、0)在。net和分析服务中使用的相同。
The closest thing to use that I found in Java is DecimalFormat which lacks some of the features (e. g. thousands and millions formatting by putting the thousands separator at the end, the floating point numbers NaN and infinity are displayed differently, etc., and probably depending on locale, there will be some additional small differences.
最接近使用Java是DecimalFormat缺少我的一些特性(e . g .格式得到成千上万的数千分离器最后,浮点数南和无穷显示不同,等等,并可能根据地区不同,会有一些额外的小差异。
For now, just the numeric formatting would suffice. Maybe date and string formatting will become a requirement in future.
现在,只要数字格式就足够了。也许日期和字符串格式将成为未来的需求。
Is there a library, or would we have to develop that ourselves?
有图书馆吗?还是我们自己开发?
I cannot imagine we are the only ones who have this issue.
我无法想象我们是唯一有这个问题的人。
POI as suggested by Noel M does not seem to offer a solution. Any other ideas?
诺埃尔·M建议的POI似乎没有提供解决方案。任何其他想法?
5 个解决方案
#1
2
Is there a library, or would we have to develop that ourselves?
有图书馆吗?还是我们自己开发?
Check ExtenXLS, the Java Spreadsheet SDK, or its open source version OpenXLS (under GPLv.3). About OpenXLS:
检查ExtenXLS、Java电子表格SDK或它的开源版本OpenXLS(在GPLv.3下面)。OpenXLS:
OpenXLS is the open-source version of ExtenXLS -- the leading Java Spreadsheet SDK.
OpenXLS是ExtenXLS的开源版本——领先的Java电子表格SDK。
OpenXLS is the no-risk way to embed advanced Java spreadsheet functionality in your applications.
OpenXLS是在应用程序中嵌入高级Java电子表格功能的无风险方法。
With the same industrial-strength code as ExtenXLS3, OpenXLS is a rock-solid performer which gives your Java applications the spreadsheet functionality your users demand -- and then some!
使用与ExtenXLS3一样的工业强度代码,OpenXLS是一个坚如磐石的执行者,它为您的Java应用程序提供用户需要的电子表格功能——然后是一些功能!
Give your users business intelligence applications and reports in the format they know and love, complete with Charts, images, VB code, and all of the features of Excel intact.
为您的用户提供商务智能应用程序和报告的格式,包括图表、图像、VB代码和Excel的所有功能。
I had a quick look at the API and found this FormatHandle#convertFormatString(String)
that converts an Excel-style format string to a Java Format string.
我快速查看了API,发现了这个FormatHandle#convertFormatString(String),它将优秀的格式字符串转换为Java格式字符串。
I don't know if it will match your constraints but it's definitely a serious product.
我不知道它是否符合你的约束条件,但它绝对是一个严肃的产品。
#3
3
No library exist for Java that does this kind of parsing. Reverse-engineering Excel to cover all test cases would be time consuming for such a niche product.
做这种解析的Java不存在库。反向工程Excel能够覆盖所有测试用例,对于这样一个利基产品来说,这将是一项费时的工作。
Since .net will convert 100% of your test cases, I suggest you focus on calling .Net in your Java application.
由于。net将100%转换您的测试用例,我建议您在Java应用程序中集中调用。net。
#4
1
for decimal format including locale and other stuff:
十进制格式,包括语言环境和其他东西:
http://www.jdocs.com/javase/7.b12/java/text/DecimalFormat.html
http://www.jdocs.com/javase/7.b12/java/text/DecimalFormat.html
http://www.freshsources.com/Format.htm
http://www.freshsources.com/Format.htm
http://www.java2s.com/Code/Java/I18N/JavaI18NFormatNumberFormat.htm
http://www.java2s.com/Code/Java/I18N/JavaI18NFormatNumberFormat.htm
You can tweak the decimalFormat output using your own custom DecimalFormatSymbols. It's posible to set the string used to represent NaN and a lot more.
您可以使用自己的自定义DecimalFormatSymbols来调整decimalFormat输出。可以设置用来表示NaN的字符串以及更多。
http://download.oracle.com/javase/6/docs/api/java/text/DecimalFormatSymbols.html
http://download.oracle.com/javase/6/docs/api/java/text/DecimalFormatSymbols.html
for Date Format:
日期格式:
http://javatechniques.com/blog/dateformat-and-simpledateformat-examples/
http://javatechniques.com/blog/dateformat-and-simpledateformat-examples/
for both in a JFormattedTextField
对于JFormattedTextField中的两者
http://www.java2s.com/Code/Java/Swing-JFC/Formatted-TextField.htm
http://www.java2s.com/Code/Java/Swing-JFC/Formatted-TextField.htm
text format
文本格式
http://www.java2s.com/Code/Java/Development-Class/MakecustomInputTextFormatterinJava.htm http://www.java2s.com/Code/Java/Development-Class/Formatter.htm http://www.java2s.com/Code/Java/Development-Class/ApplyamasktoString.htm
http://www.java2s.com/Code/Java/Development-Class/MakecustomInputTextFormatterinJava.htm http://www.java2s.com/Code/Java/Development-Class/Formatter.htm http://www.java2s.com/Code/Java/Development-Class/ApplyamasktoString.htm
#5
0
(Adding another answer as you refer to my first in your question now)
(当你提到我的第一个问题时,再加一个答案)
It seems that such a facility doesn't exist. One thing you might be able to explore is to create it yourself. You could possibly use JavaCC to express these formats yourself, and how they end up mapping to typical Java objects. JavaCC would definitely be able to give you the ability to use your own format strings.
看来这样的设施并不存在。你可以探索的一件事是自己创造它。您可以使用JavaCC自己来表达这些格式,以及它们最终如何映射到典型的Java对象。JavaCC肯定能够让您使用自己的格式字符串。
Perhaps this would fit in nicely as an implementation of NumberFormat
也许这很适合作为数字格式的实现
#1
2
Is there a library, or would we have to develop that ourselves?
有图书馆吗?还是我们自己开发?
Check ExtenXLS, the Java Spreadsheet SDK, or its open source version OpenXLS (under GPLv.3). About OpenXLS:
检查ExtenXLS、Java电子表格SDK或它的开源版本OpenXLS(在GPLv.3下面)。OpenXLS:
OpenXLS is the open-source version of ExtenXLS -- the leading Java Spreadsheet SDK.
OpenXLS是ExtenXLS的开源版本——领先的Java电子表格SDK。
OpenXLS is the no-risk way to embed advanced Java spreadsheet functionality in your applications.
OpenXLS是在应用程序中嵌入高级Java电子表格功能的无风险方法。
With the same industrial-strength code as ExtenXLS3, OpenXLS is a rock-solid performer which gives your Java applications the spreadsheet functionality your users demand -- and then some!
使用与ExtenXLS3一样的工业强度代码,OpenXLS是一个坚如磐石的执行者,它为您的Java应用程序提供用户需要的电子表格功能——然后是一些功能!
Give your users business intelligence applications and reports in the format they know and love, complete with Charts, images, VB code, and all of the features of Excel intact.
为您的用户提供商务智能应用程序和报告的格式,包括图表、图像、VB代码和Excel的所有功能。
I had a quick look at the API and found this FormatHandle#convertFormatString(String)
that converts an Excel-style format string to a Java Format string.
我快速查看了API,发现了这个FormatHandle#convertFormatString(String),它将优秀的格式字符串转换为Java格式字符串。
I don't know if it will match your constraints but it's definitely a serious product.
我不知道它是否符合你的约束条件,但它绝对是一个严肃的产品。
#2
#3
3
No library exist for Java that does this kind of parsing. Reverse-engineering Excel to cover all test cases would be time consuming for such a niche product.
做这种解析的Java不存在库。反向工程Excel能够覆盖所有测试用例,对于这样一个利基产品来说,这将是一项费时的工作。
Since .net will convert 100% of your test cases, I suggest you focus on calling .Net in your Java application.
由于。net将100%转换您的测试用例,我建议您在Java应用程序中集中调用。net。
#4
1
for decimal format including locale and other stuff:
十进制格式,包括语言环境和其他东西:
http://www.jdocs.com/javase/7.b12/java/text/DecimalFormat.html
http://www.jdocs.com/javase/7.b12/java/text/DecimalFormat.html
http://www.freshsources.com/Format.htm
http://www.freshsources.com/Format.htm
http://www.java2s.com/Code/Java/I18N/JavaI18NFormatNumberFormat.htm
http://www.java2s.com/Code/Java/I18N/JavaI18NFormatNumberFormat.htm
You can tweak the decimalFormat output using your own custom DecimalFormatSymbols. It's posible to set the string used to represent NaN and a lot more.
您可以使用自己的自定义DecimalFormatSymbols来调整decimalFormat输出。可以设置用来表示NaN的字符串以及更多。
http://download.oracle.com/javase/6/docs/api/java/text/DecimalFormatSymbols.html
http://download.oracle.com/javase/6/docs/api/java/text/DecimalFormatSymbols.html
for Date Format:
日期格式:
http://javatechniques.com/blog/dateformat-and-simpledateformat-examples/
http://javatechniques.com/blog/dateformat-and-simpledateformat-examples/
for both in a JFormattedTextField
对于JFormattedTextField中的两者
http://www.java2s.com/Code/Java/Swing-JFC/Formatted-TextField.htm
http://www.java2s.com/Code/Java/Swing-JFC/Formatted-TextField.htm
text format
文本格式
http://www.java2s.com/Code/Java/Development-Class/MakecustomInputTextFormatterinJava.htm http://www.java2s.com/Code/Java/Development-Class/Formatter.htm http://www.java2s.com/Code/Java/Development-Class/ApplyamasktoString.htm
http://www.java2s.com/Code/Java/Development-Class/MakecustomInputTextFormatterinJava.htm http://www.java2s.com/Code/Java/Development-Class/Formatter.htm http://www.java2s.com/Code/Java/Development-Class/ApplyamasktoString.htm
#5
0
(Adding another answer as you refer to my first in your question now)
(当你提到我的第一个问题时,再加一个答案)
It seems that such a facility doesn't exist. One thing you might be able to explore is to create it yourself. You could possibly use JavaCC to express these formats yourself, and how they end up mapping to typical Java objects. JavaCC would definitely be able to give you the ability to use your own format strings.
看来这样的设施并不存在。你可以探索的一件事是自己创造它。您可以使用JavaCC自己来表达这些格式,以及它们最终如何映射到典型的Java对象。JavaCC肯定能够让您使用自己的格式字符串。
Perhaps this would fit in nicely as an implementation of NumberFormat
也许这很适合作为数字格式的实现