我正在尝试生成excel文件,我的数据是HTML字符串形式。我有一个包含很少列和行的HTML表。我在java中生成一个包含n行和n列的巨大HTML表,并将该字符串保存为平面文件,并将该文件命名为mydata.html或mydata.xls。使用Microsoft Excel打开此文件时,它以列方式显示该表。该文件完全正常。这是在excel中生成文件的最简单方法。
请查找附带的示例HTML文件。将此文件另存为mydata.html或mydata.xls并使用Microsoft Excel将其打开。如果保存为.xls,请在打开时在excel对话框中单击“是”。
<!DOCTYPE html>
<html>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
border: 1px solid #dddddd;
width: 75%;
valign:top;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
valign:top;
width: 25%;
}
tr:nth-child(even) {
background-color: #dddddd;
border: 1px solid #dddddd;valign:top;
}
</style>
<body>
<table>
<tr>
<th valign="top">Column 1</th>
<th valign="top">Column 2 </th>
<th valign="top">Column 3 </th>
</tr>
<tr>
<td valign="top">Row 1 Column 1</td>
<td valign="top">
<p>
<b>Paragraph 1 </b>. This is a large text which spills over multiple lines.Java is at the heart of our digital lifestyle. It's the platform for launching careers, exploring human-to-digital interfaces, architecting the world's best applications, and unlocking innovation everywhere from garages to global organizations. When it comes to building computer programming skills, learning Java will take you way beyond the games of your childhood. Knowing Java will be a clear advantage in your future career. Learning Java can be a skill for a career, or a skill for fun or both. Students of all ages have built amazing things, from hobby projects to world-changing initiatives. Oracle Academy Workshops are designed to make first experiences with computing fun and engaging, while still leveraging best academic curriculum practices like project-based learning and offering educators methods for assessment. Oracle Academy Workshops are best used by educators in one of three ways: to introduce students, including students as young as late primary school ages, to computer science in a fun and engaging way;
to incorporate exposure to computer science into the teaching of other academic disciplines; and
to offer a limited introduction to computer science to students via extra-curricular programs and/or workshop experiences.
</p>
<p><b>Paragraph 2 </b> --> Like our Getting Started with Java Using Alice Workshop, this freely available course is designed for teachers, students and individuals with little or no programming experience and teaches basic Java programming concepts through developing 3-D animations in Alice 3.1. Alice is a free, educational, introductory Java development environment created at Carnegie Mellon University. While it is suitable for all beginning learners, it can be especially engaging for girls. Learners will have fun creating animated stories and games using objects and characters from a rich gallery of 3-D models.
</p>
<p><b>Paragraph 3 </b> Oracle Academy Workshops are also available to Individual and Institutional members in Workshop in a Box formats to facilitate the delivery of introductory computer science workshops by parents, volunteers, computer club sponsors and educators who may not specialize in teaching computer science</p>
</td>
<td valign="top">
<p>
<b>Paragraph 1 </b>.
When you learn Java, youre learning more than just a language. Because Java is a technology platform with many interconnected capabilities that can give cutting-edge, in-demand job skills. In fact, Java tops Inc.coms list of the ten most popular programming languages. Java can take you where you want to go. Learn how to create games, simulations and other graphical programs using basic Java programming via free educational Java development environments from Carnegie Mellon University (Alice) and the University of Kent (Greenfoot). No prior programming or computer science experience is required.
</p>
<p>
<b>Paragraph 2 </b>.
Oracle Academy self-study courses are designed to provide a self-paced learning experience for teachers, students and individuals.
</p>
<p><b>Paragraph 3 </b>Oracle Academy Workshop in a Box are designed to facilitate the delivery of introductory computer science workshops by parents, volunteers, computer club sponsors and educators who may not specialize in teaching computer science.
</p>
</td>
</tr>
</table>
</body>
</html>
&#13;
但是,我面临一个主要问题。任何段落(P标记)或换行符(使用
标记)都会导致相邻单元格跳转到下一行。请使用excel打开附加的HTML文件。第2列和第3列中有3个段落。请注意第3栏第2段的调整。第3栏的第2段并不在第1段之后开始,而是与第2栏第2段的同一行开头。段落上方有很多空格我希望段落2应该在段落1之后开始。如果在浏览器中打开html文件,则段落的对齐是完美的。
答案 0 :(得分:0)
您可以使用换行符<br>
代替段落标记<p>
,只需添加样式.... style="mso-data-placement:same-cell;"
..这是您的示例
<!DOCTYPE html>
<html>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
border: 1px solid #dddddd;
width: 75%;
valign:top;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
valign:top;
width: 25%;
}
tr:nth-child(even) {
background-color: #dddddd;
border: 1px solid #dddddd;valign:top;
}
</style>
<body>
<table>
<tr>
<th valign="top">Column 1</th>
<th valign="top">Column 2 </th>
<th valign="top">Column 3 </th>
</tr>
<tr>
<td valign="top">Row 1 Column 1</td>
<td valign="top">
<b>Paragraph 1 </b>. This is a large text which spills over multiple lines.Java is at the heart of our digital lifestyle. It's the platform for launching careers, exploring human-to-digital interfaces, architecting the world's best applications, and unlocking innovation everywhere from garages to global organizations. When it comes to building computer programming skills, learning Java will take you way beyond the games of your childhood. Knowing Java will be a clear advantage in your future career. Learning Java can be a skill for a career, or a skill for fun or both. Students of all ages have built amazing things, from hobby projects to world-changing initiatives. Oracle Academy Workshops are designed to make first experiences with computing fun and engaging, while still leveraging best academic curriculum practices like project-based learning and offering educators methods for assessment. Oracle Academy Workshops are best used by educators in one of three ways: to introduce students, including students as young as late primary school ages, to computer science in a fun and engaging way;
to incorporate exposure to computer science into the teaching of other academic disciplines; and
to offer a limited introduction to computer science to students via extra-curricular programs and/or workshop experiences.
<br style="mso-data-placement:same-cell;" />
<b>Paragraph 2 </b> --> Like our Getting Started with Java Using Alice Workshop, this freely available course is designed for teachers, students and individuals with little or no programming experience and teaches basic Java programming concepts through developing 3-D animations in Alice 3.1. Alice is a free, educational, introductory Java development environment created at Carnegie Mellon University. While it is suitable for all beginning learners, it can be especially engaging for girls. Learners will have fun creating animated stories and games using objects and characters from a rich gallery of 3-D models.
<br style="mso-data-placement:same-cell;" />
<b>Paragraph 3 </b> Oracle Academy Workshops are also available to Individual and Institutional members in Workshop in a Box formats to facilitate the delivery of introductory computer science workshops by parents, volunteers, computer club sponsors and educators who may not specialize in teaching computer science
<br style="mso-data-placement:same-cell;" />
</td>
<td valign="top">
<b>Paragraph 1 </b>.
When you learn Java, youre learning more than just a language. Because Java is a technology platform with many interconnected capabilities that can give cutting-edge, in-demand job skills. In fact, Java tops Inc.coms list of the ten most popular programming languages. Java can take you where you want to go. Learn how to create games, simulations and other graphical programs using basic Java programming via free educational Java development environments from Carnegie Mellon University (Alice) and the University of Kent (Greenfoot). No prior programming or computer science experience is required.
<br style="mso-data-placement:same-cell;" />
<b>Paragraph 2 </b>.
Oracle Academy self-study courses are designed to provide a self-paced learning experience for teachers, students and individuals.
<br style="mso-data-placement:same-cell;" />
<b>Paragraph 3 </b>Oracle Academy Workshop in a Box are designed to facilitate the delivery of introductory computer science workshops by parents, volunteers, computer club sponsors and educators who may not specialize in teaching computer science.
<br style="mso-data-placement:same-cell;" />
</td>
</tr>
</table>
</body>
</html>
&#13;