从html生成excel

我想生成Excel文件,我的数据是以HTMLstring的forms。 我有一个很less的列和行的HTML表格。 我在java中生成了一个具有n行和n列的巨大HTML表,并将该string保存到一个平面文件中,并将该文件命名为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> 

但是,我面临着一个重大问题。 任何段落(P标签)或换行符(使用
标记)导致相邻单元跳转到下一行。 请使用excel打开附加的HTML文件。 第2栏和第3栏有3个段落。 请注意第3栏第2段的alignment。第3栏第2段不是从第1段开始,而是从第2栏的第2段开始。第2段的上方有许多空格第3列。我希望段落2应该在段落1之后开始。如果html文件在浏览器中打开,段落的alignment是完美的。

我想第2段应该在第1段之后开始。请find附加的图像文件。 在这里输入图像说明

您可以使用换行符标记<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>