如何在将数据从 excel 导出到 evernote 时保留格式
How can I preserve the format while exporting data from excel to evernote
我在 excel 中有以下代码,它将每一行和每一列的数据导入到每一行的单个注释中。
但它不会像 excel 中那样格式化数据,而是按原样打印单元格内容。
这是我导入 .enex 文件后的样子
这是它在 excel.
中的样子
Code
Option Explicit
Sub OutputNotesXML()
Dim iRow As Long
Close #1
With ActiveSheet
'For iRow = 2 To 2
Open ThisWorkbook.Path & "\evernote-import.enex" For Output As #1
Print #1, "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>"
Print #1, "<!DOCTYPE en-export SYSTEM " & Chr(34) & "http://xml.evernote.com/pub/evernote-export.dtd" & Chr(34) & ">"
Print #1, "<en-export export-date=" & Chr(34) & "20120202T073208Z" & Chr(34) & " application=" & Chr(34) & "Evernote/Windows" & Chr(34) & " version=" & Chr(34) & "4.x" & Chr(34) & ">"
For iRow = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row
Print #1, "<note><title>"
Print #1, .Cells(iRow, "A").Value 'Title
Print #1, "</title><content><![CDATA[<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>"
Print #1, "<!DOCTYPE en-note SYSTEM " & Chr(34) & "http://xml.evernote.com/pub/enml2.dtd" & Chr(34) & ">"
Print #1, "<en-note style=" & Chr(34) & "word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" & Chr(34) & ">"
Print #1, CBr(.Cells(iRow, "B").Value) & vbNewLine 'Note
Print #1, CBr(.Cells(iRow, "C").Value) & vbNewLine 'Note
Print #1, CBr(.Cells(iRow, "D").Value) & vbNewLine 'Note
Print #1, CBr(.Cells(iRow, "E").Value) 'Note
Print #1, CBr(.Cells(iRow, "F").Value) 'Note
Print #1, CBr(.Cells(iRow, "G").Value) 'Note
Print #1, CBr(.Cells(iRow, "H").Value) 'Note
Print #1, CBr(.Cells(iRow, "I").Value) 'Note
Print #1, CBr(.Cells(iRow, "J").Value) 'Note
Print #1, CBr(.Cells(iRow, "K").Value) 'Note
Print #1, CBr(.Cells(iRow, "L").Value) 'Note
Print #1, CBr(.Cells(iRow, "M").Value) 'Note
Print #1, CBr(.Cells(iRow, "N").Value) 'Note
Print #1, CBr(.Cells(iRow, "O").Value) 'Note
Print #1, CBr(.Cells(iRow, "P").Value) 'Note
Print #1, CBr(.Cells(iRow, "Q").Value) 'Note
Print #1, CBr(.Cells(iRow, "R").Value) 'Note
Print #1, CBr(.Cells(iRow, "S").Value) 'Note
Print #1, CBr(.Cells(iRow, "T").Value) 'Note
Print #1, CBr(.Cells(iRow, "U").Value) 'Note
Print #1, CBr(.Cells(iRow, "V").Value) 'Note
Print #1, CBr(.Cells(iRow, "W").Value) 'Note
Print #1, CBr(.Cells(iRow, "X").Value) 'Note
Print #1, CBr(.Cells(iRow, "Y").Value) 'Note
Print #1, CBr(.Cells(iRow, "Z").Value) 'Note
Print #1, CBr(.Cells(iRow, "AA").Value) 'Note
Print #1, CBr(.Cells(iRow, "AB").Value) 'Note
Print #1, CBr(.Cells(iRow, "AC").Value) 'Note
Print #1, "</en-note>]]></content><created>"
'Print #1, .Cells(iRow, "D").Text 'Created Date in Evernote Time Format...
'To get the evernote time, first convert your time to Zulu/UTC time.
'Put this formula in Column D: =C2+TIME(6,0,0) where 6 is the hours UTC is ahead of you.
'Then right click on your date column, select format, then select custom. Use this custom code: yyyymmddThhmmssZ
Print #1, "</created><updated>201206025T000001Z</updated></note>"
Next iRow
Print #1, "</en-export>"
Close #1
End With
End Sub
Function CBr(val) As String
'parse hard breaks into to HTML breaks
CBr = Replace(val, Chr(13), "")
CBr = Replace(CBr, "&", "&")
End Function
'I modified this code from Marty Zigman's post here: http://blog.prolecto.com/2012/01/31/importing-excel-data-into-evernote-without-a-premium-account/
Evernote 笔记的内容在 ENML, which is a superset of xHTML. You'll see that the list of permitted elements 中,包括 <table>
、<tr>
和 <td>
等标签,因此您可以使用它们构建 [=22] =] table为笔记内容
另一种解决方案是通过 CSS 来完成。需要注意的是,CSS 必须作为内联样式放入每个元素的 style
属性中。请注意,还支持 <br/>
标签。
我建议您首先在 Evernote 中手动构建一个看起来像您想要的笔记,然后将该笔记导出到 ENEX。然后您可以检查 ENEX 文件以查看需要如何格式化。
我注意到的一件关键事情是 Evernote 应用程序本身广泛使用 HTML <div>
标签,而不是 <p>
或 <br>
,以实现没有行行与行之间的空格。
如果您希望 EN Note 将数据显示为 table,如 Excel,那么您需要在您的文件中使用 HTML <table>
标签输出。
我在 excel 中有以下代码,它将每一行和每一列的数据导入到每一行的单个注释中。
但它不会像 excel 中那样格式化数据,而是按原样打印单元格内容。
这是我导入 .enex 文件后的样子
Code
Option Explicit
Sub OutputNotesXML()
Dim iRow As Long
Close #1
With ActiveSheet
'For iRow = 2 To 2
Open ThisWorkbook.Path & "\evernote-import.enex" For Output As #1
Print #1, "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>"
Print #1, "<!DOCTYPE en-export SYSTEM " & Chr(34) & "http://xml.evernote.com/pub/evernote-export.dtd" & Chr(34) & ">"
Print #1, "<en-export export-date=" & Chr(34) & "20120202T073208Z" & Chr(34) & " application=" & Chr(34) & "Evernote/Windows" & Chr(34) & " version=" & Chr(34) & "4.x" & Chr(34) & ">"
For iRow = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row
Print #1, "<note><title>"
Print #1, .Cells(iRow, "A").Value 'Title
Print #1, "</title><content><![CDATA[<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>"
Print #1, "<!DOCTYPE en-note SYSTEM " & Chr(34) & "http://xml.evernote.com/pub/enml2.dtd" & Chr(34) & ">"
Print #1, "<en-note style=" & Chr(34) & "word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" & Chr(34) & ">"
Print #1, CBr(.Cells(iRow, "B").Value) & vbNewLine 'Note
Print #1, CBr(.Cells(iRow, "C").Value) & vbNewLine 'Note
Print #1, CBr(.Cells(iRow, "D").Value) & vbNewLine 'Note
Print #1, CBr(.Cells(iRow, "E").Value) 'Note
Print #1, CBr(.Cells(iRow, "F").Value) 'Note
Print #1, CBr(.Cells(iRow, "G").Value) 'Note
Print #1, CBr(.Cells(iRow, "H").Value) 'Note
Print #1, CBr(.Cells(iRow, "I").Value) 'Note
Print #1, CBr(.Cells(iRow, "J").Value) 'Note
Print #1, CBr(.Cells(iRow, "K").Value) 'Note
Print #1, CBr(.Cells(iRow, "L").Value) 'Note
Print #1, CBr(.Cells(iRow, "M").Value) 'Note
Print #1, CBr(.Cells(iRow, "N").Value) 'Note
Print #1, CBr(.Cells(iRow, "O").Value) 'Note
Print #1, CBr(.Cells(iRow, "P").Value) 'Note
Print #1, CBr(.Cells(iRow, "Q").Value) 'Note
Print #1, CBr(.Cells(iRow, "R").Value) 'Note
Print #1, CBr(.Cells(iRow, "S").Value) 'Note
Print #1, CBr(.Cells(iRow, "T").Value) 'Note
Print #1, CBr(.Cells(iRow, "U").Value) 'Note
Print #1, CBr(.Cells(iRow, "V").Value) 'Note
Print #1, CBr(.Cells(iRow, "W").Value) 'Note
Print #1, CBr(.Cells(iRow, "X").Value) 'Note
Print #1, CBr(.Cells(iRow, "Y").Value) 'Note
Print #1, CBr(.Cells(iRow, "Z").Value) 'Note
Print #1, CBr(.Cells(iRow, "AA").Value) 'Note
Print #1, CBr(.Cells(iRow, "AB").Value) 'Note
Print #1, CBr(.Cells(iRow, "AC").Value) 'Note
Print #1, "</en-note>]]></content><created>"
'Print #1, .Cells(iRow, "D").Text 'Created Date in Evernote Time Format...
'To get the evernote time, first convert your time to Zulu/UTC time.
'Put this formula in Column D: =C2+TIME(6,0,0) where 6 is the hours UTC is ahead of you.
'Then right click on your date column, select format, then select custom. Use this custom code: yyyymmddThhmmssZ
Print #1, "</created><updated>201206025T000001Z</updated></note>"
Next iRow
Print #1, "</en-export>"
Close #1
End With
End Sub
Function CBr(val) As String
'parse hard breaks into to HTML breaks
CBr = Replace(val, Chr(13), "")
CBr = Replace(CBr, "&", "&")
End Function
'I modified this code from Marty Zigman's post here: http://blog.prolecto.com/2012/01/31/importing-excel-data-into-evernote-without-a-premium-account/
Evernote 笔记的内容在 ENML, which is a superset of xHTML. You'll see that the list of permitted elements 中,包括 <table>
、<tr>
和 <td>
等标签,因此您可以使用它们构建 [=22] =] table为笔记内容
另一种解决方案是通过 CSS 来完成。需要注意的是,CSS 必须作为内联样式放入每个元素的 style
属性中。请注意,还支持 <br/>
标签。
我建议您首先在 Evernote 中手动构建一个看起来像您想要的笔记,然后将该笔记导出到 ENEX。然后您可以检查 ENEX 文件以查看需要如何格式化。
我注意到的一件关键事情是 Evernote 应用程序本身广泛使用 HTML <div>
标签,而不是 <p>
或 <br>
,以实现没有行行与行之间的空格。
如果您希望 EN Note 将数据显示为 table,如 Excel,那么您需要在您的文件中使用 HTML <table>
标签输出。