Java 使用XMLTransformer.transformXLS,但无法将xls模板中的格式保留到生成的xls文件 synchronized public void转换( 转换语境, OutputStream(o)引发ServiceException{ BufferedInputStream templateInputStream=null; 字符串classPathLocation=!context.getType().getTemplate().startsWith(“/”) ?“/”+context.getType().getTemplate() :context.getType().getTemplate(); URL templateURL=ClassLoader.class.getResource(classPathLocation); templateInputStream=新的BufferedInputStream(templateURL.openStream()); 工作簿工作簿=xlsTransformer.transformXLS(templateInputStream,context.getContext()); 练习册。写(o); templateInputStream.close(); o、 冲洗(); o、 close(); }

Java 使用XMLTransformer.transformXLS,但无法将xls模板中的格式保留到生成的xls文件 synchronized public void转换( 转换语境, OutputStream(o)引发ServiceException{ BufferedInputStream templateInputStream=null; 字符串classPathLocation=!context.getType().getTemplate().startsWith(“/”) ?“/”+context.getType().getTemplate() :context.getType().getTemplate(); URL templateURL=ClassLoader.class.getResource(classPathLocation); templateInputStream=新的BufferedInputStream(templateURL.openStream()); 工作簿工作簿=xlsTransformer.transformXLS(templateInputStream,context.getContext()); 练习册。写(o); templateInputStream.close(); o、 冲洗(); o、 close(); },java,xml,excel,templates,Java,Xml,Excel,Templates,来自OP的评论:- 我有一个特定的xls,我正在使用它作为模板,我正在尝试使用该模板生成另一个excel。。但是生成的模板使用的是某种外国语言,这可能是一个unicode问题,而且模板的字体和格式也没有保留请澄清您的具体问题或添加其他详细信息,以突出显示您需要的内容。正如目前所写的,很难准确地说出您的要求。标签?您可以选择通过标记显式输出,而不是使用空格/文本作为输出。我有一个特定的xls作为模板,我正在尝试使用该模板生成另一个excel。。但生成的模板使用的是某种外国语言,这可能是一个unic

来自OP的评论:-


我有一个特定的xls,我正在使用它作为模板,我正在尝试使用该模板生成另一个excel。。但是生成的模板使用的是某种外国语言,这可能是一个unicode问题,而且模板的字体和格式也没有保留

请澄清您的具体问题或添加其他详细信息,以突出显示您需要的内容。正如目前所写的,很难准确地说出您的要求。
标签?您可以选择通过标记显式输出,而不是使用空格/文本作为输出。我有一个特定的xls作为模板,我正在尝试使用该模板生成另一个excel。。但生成的模板使用的是某种外国语言,这可能是一个unicode问题,而且模板的字体和格式也没有保留
synchronized public void transform(
    TransformationContext<Map<String, Object>> context,
    OutputStream o) throws ServiceException{
  BufferedInputStream templateInputStream = null;

  String classPathLocation = !context.getType().getTemplate().startsWith("/")
      ? "/" + context.getType().getTemplate() 
      : context.getType().getTemplate();

  URL templateURL = ClassLoader.class.getResource(classPathLocation);

  templateInputStream = new BufferedInputStream(templateURL.openStream());

  Workbook workbook = xlsTransformer.transformXLS(templateInputStream, context.getContext());
  workbook.write(o);

  templateInputStream.close();
  o.flush();
  o.close();
}