将Word或者Excel里的表格拷贝到剪贴板里,数据是使用tab和回车分割的。可以编写一个程序来分析剪贴板的数据,转换成HTML和CALS表格。这在没有合并单元格的情况下工作良好。
在剪贴板数据中,没有发现表示单元格合并的信息。如果在数据中有合并的单元格,以上程序不能处理。
如果从Excel中复制一个表格(带单元格合并),然后粘贴到Word中,合并的单元格被正确地粘贴到Word中。从这种结果猜测,从Excel到Word的复制、粘贴过程中,程序是能取到单元格合并的信息的。是不是它使用了有别于windows的拷贝、粘贴的方法。
朋友们有什么好办法?
================================================================================
using System.Windows.Forms;
IDataObject iData = Clipboard.GetDataObject(); object obj = null; obj = iData.GetData("HTML Format"); String rtn =obj.ToString(); |
示例值 :
Version:1.0 StartHTML:0000000105 EndHTML:0000002328 StartFragment:0000001917 EndFragment:0000002276 <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv=Content-Type content="text/html; charset=utf-8"> <meta name=ProgId content=Excel.Sheet> <meta name=Generator content="Microsoft Excel 12"> <link id=Main-File rel=Main-File href="file:///C:/DOCUME~1/LJINGJ~1.INF/LOCALS~1/Temp/msohtmlclip1/01/clip.htm"> <link rel=File-List href="file:///C:/DOCUME~1/LJINGJ~1.INF/LOCALS~1/Temp/msohtmlclip1/01/clip_filelist.xml"> <style> <!--table {mso-displayed-decimal-separator:"/."; mso-displayed-thousand-separator:"/,";} @page {margin:.75in .7in .75in .7in; mso-header-margin:.3in; mso-footer-margin:.3in;} tr {mso-height-source:auto; mso-ruby-visibility:none;} col {mso-width-source:auto; mso-ruby-visibility:none;} br {mso-data-placement:same-cell;} td {padding-top:1px; padding-right:1px; padding-left:1px; mso-ignore:padding; color:black; font-size:11.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:瀹嬩綋; mso-generic-font-family:auto; mso-font-charset:134; mso-number-format:General; text-align:general; vertical-align:middle; border:none; mso-background-source:auto; mso-pattern:auto; mso-protection:locked visible; white-space:nowrap; mso-rotate:0;} ruby {ruby-align:left;} rt {color:windowtext; font-size:9.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:瀹嬩綋; mso-generic-font-family:auto; mso-font-charset:134; mso-char-type:none; display:none;} --> </style> </head> <body link=blue vlink=purple> <table border=0 cellpadding=0 cellspacing=0 width=144 style='border-collapse: collapse;width:108pt'> <!--StartFragment--> <col width=72 span=2 style='width:54pt'> <tr height=18 style='height:13.5pt'> <td height=18 align=right width=72 style='height:13.5pt;width:54pt'>11 </td> <td align=right width=72 style='width:54pt'>12 </td> </tr> <tr height=18 style='height:13.5pt'> <td height=18 align=right style='height:13.5pt'>21 </td> <td align=right>22 </td> </tr> <!--EndFragment--> </table> </body> </html> |