Dépôt officiel du code source de l'ERP OpenConcerto
Blame | Last modification | View Log | RSS feed
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.utils.ooxml;
import java.text.DecimalFormat;
import java.text.Format;
import java.text.SimpleDateFormat;
public class XLSXFormat {
private final int id;
private final String format;
private boolean isDateFormat = false;
private Format jformat;
public XLSXFormat(int id, String format) {
this.id = id;
this.format = format;
final String f = format.toLowerCase();
if (f.contains("mm") || f.contains("dd") || f.contains("yy")) {
this.isDateFormat = true;
}
}
public XLSXFormat(int id, String format, boolean date) {
this.id = id;
this.format = format;
this.isDateFormat = date;
}
public int getId() {
return this.id;
}
public String getFormat() {
return this.format;
}
public boolean isDateFormat() {
return this.isDateFormat;
}
public String format(String txt) {
if (this.format.equalsIgnoreCase("general")) {
return txt;
}
if (this.jformat == null) {
String javaFormat = this.format.replace("YYYY", "yyyy");
javaFormat = javaFormat.replace("YY", "yy");
javaFormat = javaFormat.replace("mm", "MM");
javaFormat = javaFormat.replace("dd", "DD");
if (this.isDateFormat) {
this.jformat = new SimpleDateFormat(javaFormat);
} else {
this.jformat = new DecimalFormat(javaFormat);
}
}
return this.jformat.format(txt);
}
}