通过剪贴板将HTML表格导入Excel [英] Importing HTML Table into Excel via clipboard

查看:108
本文介绍了通过剪贴板将HTML表格导入Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的应用程序中将表格数据复制到Excel。到目前为止,我发现的最简单的方法是使用HTML作为中间格式。阅读这个问题后,我可以保留格式我的数据。有没有办法保持列的宽度?我尝试以各种方式设置样式:

 < td style =width:100;> ... < / TD> 
< td style =width:100px;> ...< / td>
< td style =width:100pt;> ...< / td>

但无济于事。任何想法?



对于奖励积分,有没有一个地方可以找到Excel的HTML格式描述?

更新:我写了一个小工具来转储传输类型XML样式表。这是一个自包含的XML文档。它也包含列宽。但是一个快速测试表明,即使我在两个表格之间剪切和粘贴时,Excel也会完全忽略列宽:(因此,除非有人能告诉我一个更改此行为的选项,否则我认为根本无法在粘贴时格式化列。



我找到了一个方法,粘贴完成后,右下角会出现一个小图标,看起来像工具栏上的粘贴按钮。您可以选择一些选项,一种是保留源表的宽度。

解决方案

我推荐XML Spreadsheet格式2002/2003之一 - 更简单的生成)超过Excel导入HTML的能力。



我已经完成了两个和书面库来直接从.NET中导出,而且XML格式绝对不太可能让你失眠。


I want to copy tabular data to Excel from my app. The most simple way I found so far was using HTML as the intermediary format. After reading this question, I could preserve the formatting of my data. Is there a way to keep the width of the columns, too? I tried to set the style in various ways:

<td style="width:100;">...</td>
<td style="width:100px;">...</td>
<td style="width:100pt;">...</td>

but to no avail. Any ideas?

For bonus points, is there a place where I can find a description of Excel's HTML "format"?

[EDIT] Update: I've written a small tool to dump the transfer type "XML Stylesheet". This is a self contained XML document. It also contains column widths. But a quick test shows that Excel ignores the column widths completely, even when I cut&paste between two tables :( So unless someone can tell me an option to change this behavior, I guess it's simply not possible to format the columns while pasting.

[EDIT2] I've found a way. After pasting, you get a little icon in the lower right corner which looks like the paste button in the toolbar. Here, you can select some options. One is "Keep width of source table".

解决方案

I recommend the XML Spreadsheet format (the old 2002/2003 one--simpler to generate) over Excel's ability to import HTML.

I've done both and written libraries to export both directly from .NET, and the XML format is definitely less likely to make you lose sleep.

这篇关于通过剪贴板将HTML表格导入Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆