我正在尝试使用docx4j将带有垂直方向文本的html表格转换为docx。这是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="ISO-8859-1" />
<title>Platilla HTML para convertirlo a DOCX</title>
<style type="text/css">
body {
font-family:Arial;
font-size:11pt;
}
.titulo {
text-align:center;
font-weight:bold;
}
.contenido {
text-align:justify;
}
.tabla {
width:100%;
border:1px solid black;
border-spacing:0px;
border-collapse:collapse;
margin-top: 10px;
}
.tabla td, .tabla th {
border:1px solid black;
}
.tabla th {
background-color: #898989;
color: white;
text-align: center;
vertical-align: bottom;
height: 150px;
padding-bottom: 3px;
padding-left: 5px;
padding-right: 5px;
}
.verticalText {
text-align: center;
vertical-align: middle;
width: 20px;
margin: 0px;
padding: 0px;
padding-left: 3px;
padding-right: 3px;
padding-top: 10px;
white-space: nowrap;
transform: rotate(-90deg);
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
};
</style>
</head>
<body>
<table class="tabla">
<tr>
<th><div class="verticalText">No. de Item</div></th>
<th>Departamento / Municipio</th>
<th>Tipo de Servicio</th>
<th>Contratista</th>
<th>Monto maximo</th>
</tr>
<tr>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
</tr>
</table>
</body>
我正在使用样式将文本转换为垂直方向...
transform: rotate(-90deg);
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
...但是当我使用docxj4从html导出到docx时(在变量“xhtml”中是要导出的所有html代码)...
private WordprocessingMLPackage export(String xhtml) {
WordprocessingMLPackage wordMLPackage = null;
try {
RFonts arialRFonts = Context.getWmlObjectFactory().createRFonts();
arialRFonts.setAscii("Arial");
arialRFonts.setHAnsi("Arial");
XHTMLImporterImpl.addFontMapping("Arial", arialRFonts);
wordMLPackage = WordprocessingMLPackage.createPackage(PageSizePaper.LETTER, false);
XHTMLImporter importer = new XHTMLImporterImpl(wordMLPackage);
List<Object> content = importer.convert(xhtml, null);
wordMLPackage.getMainDocumentPart().getContent().addAll(content);
} catch (Docx4JException ex) {
Logger.getLogger(ReporteContratoEspecialista.class.getName()).log(Level.SEVERE, null, ex);
}
return wordMLPackage;
}
..保存文件......
wordMLPackage.save(servletOutputStream);
...单元格文本在.docx文档中处于正常方向,水平方向。
有没有其他方法可以使用html生成docx文档? 我需要docx中的文本垂直。