I want to export from Java/JSP/Displaytag to Excel format. Some values of my array start with '+' (or other Excel restricted characters like '=', ...).
When i do it, Excel replace the value by "#NAME?".
When i try to add the "'" before my string value, all rows got a "'" (it's not what i want).
When i try to add the '"' before and after my string value, all rows have it like this : "<my value>" (it's not what i want).
How can we do it ?
I search in the documentation but dont found it.
Thanks for your answer.
Boly
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
public class StringExcelExportDisplayTagWrapper implements DisplaytagColumnDecorator {
final static Logger log = Logger.getLogger(StringExcelExportDisplayTagWrapper.class);
publicObjectdecorate(ObjectcolumnValue,PageContextpageContext,MediaTypeEnummedia)throwsDecoratorException{
Strings=(String)columnValue;if((s!=null)&& s.length()>0) {if(!Pattern.matches("[a-zA-Z]", s.substring(0,1))) {log.debug("decorate(...) : Cell [" + s + "] contain special char => replaced by [=\"" + s + "\"]");s=(Object)"=\"" + s + "\"";}
}returns;
}
}
Regards
Boly
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi everybody,
I want to export from Java/JSP/Displaytag to Excel format. Some values of my array start with '+' (or other Excel restricted characters like '=', ...).
When i do it, Excel replace the value by "#NAME?".
When i try to add the "'" before my string value, all rows got a "'" (it's not what i want).
When i try to add the '"' before and after my string value, all rows have it like this : "<my value>" (it's not what i want).
How can we do it ?
I search in the documentation but dont found it.
Thanks for your answer.
Boly
it's OK, i found an alternate way to display string values starting with a special char :
=> by replacing <value> to ="<value>".
In JSP, i declare a decorator like this :
And this is the source of my decorator (StringExcelExportDisplayTagWrapper.java):
import java.util.regex.Pattern;
import javax.servlet.jsp.PageContext;
import org.apache.log4j.Logger;
import org.displaytag.decorator.DisplaytagColumnDecorator;
import org.displaytag.exception.DecoratorException;
import org.displaytag.properties.MediaTypeEnum;
public class StringExcelExportDisplayTagWrapper implements DisplaytagColumnDecorator {
final static Logger log = Logger.getLogger(StringExcelExportDisplayTagWrapper.class);
}
Regards
Boly