将带有colspan的HTML表复制/粘贴到Excel? [英] Copy/paste HTML table with colspan to Excel?

查看:66
本文介绍了将带有colspan的HTML表复制/粘贴到Excel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:在OSX上,复制/粘贴可以从Firefox完美运行,但不能从Chrome或Safari

是否可以将具有colspan的表单元格复制到反映结构的Excel中?

Is it possible to copy table cells with colspan to Excel that reflects the structure?

想要一个应用程序以HTML格式呈现表格,以便用户可以很好地将其复制/粘贴到Excel.特别是,希望某些具有 colspan =#的表单元格以正确的对齐方式复制到Excel.

Would like an app to render tables in HTML such that a user can copy/paste it to Excel reasonably well. In particular, would like some table cells with colspan=# to copy to Excel with correct alignment.

问题在于Excel在复制/粘贴中似乎忽略了colspan.因此,在下面的示例中,列标题大小"在黄色"列的左侧显示得太左,而在黄色"列的上方显示了

The problem is that Excel seems to ignore colspan in copy/paste. Thus in the example below the column title "Size" appears too far to the left, over the column for "Yellow" when it should appear over the column for "small"

我并不特别关心Excel单元格是合并",跨选择集中"还是仅是单独的单元格.他们的关键是要使位置在语义上正确.

I don't particularly care if the Excel cell is "merged", "centered across selection" or just plain separate cells. They key thing is to have the position be semantically correct.

可以使用HTML5,也可以进行任何破解

HTML5 okay as well as any hack

CodePen : http://codepen.io/gradualstudent/pen/MYwNpY

在浏览器中呈现的HTML表:

复制/粘贴到Excel后的表格:

推荐答案

剪贴板的处理方式在不同的浏览器中有所不同.Excel是否可以以正确的格式从剪贴板中获取表格,取决于哪些数据在剪贴板中放置了不同的浏览器.不幸的是,默认情况下,最实际的操作系统并没有带有剪贴板查看器.所以我们不能简单地看那里有什么区别.

The Clipboard handling differ in different browsers. Whether Excel can get a table from the clipboard in the correct format depends on which data have the different browsers put in the clipboard. Unfortunately the most actual operating systems comes not more with a clipboard viewer per default. So we cannot simply look there what the differences are.

但是Excel可以处理HTML表.因此,如果剪贴板中有HTML表的HTML源代码,则Excel可以正确地粘贴它.

But Excel can deal with HTML tables. And so if HTML source code of a HTML table is in the clipboard, then Excel can paste this properly.

使用VBA的示例:

Sub HTMLinClipboardTest()

 sHTML = "<table>" & _
         "<tr><td colspan=""2"" align=""center"">colspan2</td></tr>" & _
         "<tr><td rowspan=""2"" style=""vertical-align:middle;"">rowspan2</td><td>default</td></tr>" & _
         "<tr><td>default</td></tr>" & _
         "<tr><td>default</td><td>default</td></tr>" & _
         "</table>"

 Dim oDataObject As New DataObject 'needs Microsoft Forms 2.0 Object Library
 oDataObject.SetText sHTML
 oDataObject.PutInClipboard
 ActiveSheet.Range("a1").Select
 ActiveSheet.Paste

End Sub

这篇关于将带有colspan的HTML表复制/粘贴到Excel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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