如何在将数据从excel导出到evernote时保留格式

时间:2016-02-03 13:32:50

标签: xml excel vba import evernote

我在excel中有以下代码,它将每行和每列的数据导入到每行的一个注释中。

但它不会像在Excel中那样格式化数据,而只是按原样打印单元格内容。

这就是我在制作.enex文件时的样子

Screenshot of the imported data 这就是它在excel中的表现。

enter image description here

  

代码

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, "&", "&amp;")
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/

2 个答案:

答案 0 :(得分:2)

Evernote笔记的内容位于ENML,这是xHTML的超集。您会看到permitted elements列表包含<table><tr><td>等标记,因此您可以使用这些标记为注释内容构建html表格

另一种解决方案是通过CSS来实现。需要注意的是,CSS必须在每个元素的style属性中作为内联样式。请注意,也支持<br/>标记。

答案 1 :(得分:0)

我建议您首先在Evernote中手动构建一个看起来就像您想要它的Note,然后将该Note导出到ENEX。然后,您可以检查ENEX文件以查看需要格式化的内容。

我注意到的一个关键点是,Evernote应用程序本身广泛使用HTML <div>标记,而不是<p><br>,以实现行之间没有空格的行。 / p>

如果您希望EN注释以Excel格式显示数据,则需要在输出中使用HTML <table>标记。