从文本文件中导入excel,并带有样式
我有一个保存文本文件的程序,我想要做的是添加一些基本的样式到这个文本,然后在Excel中打开。
我的文件通常是这样的:
Title of text lorem ipsum dolor sit amet
有什么我可以写在这个文本文件,将使“ 文本标题 ”在Excel中打开时加粗 ?
就像html标签一样
<b>Title of text</b> lorem ipsum dolor sit amet
有没有什么类似的Excel?
你可以使用下面的代码。 此代码将格式化范围A1:A13
文本。 您可以根据需要select要格式化的范围。 只需将此代码复制到Visual Basic编辑器,并使用运行子button运行子。
Sub Macro1() Dim str As String Dim nBold As Long Dim nEndBold As Long Dim nChars As Long Set Rng = Range("A1:A13") For Each cell In Rng str = cell.Text nBold = InStr(str, "<b>") If nBold > 0 Then nEndBold = InStr(str, "</b>") If nEndBold = 0 Then nEndBold = 32767 nChars = nEndBold - nBold - 3 str = Replace(Replace(str, "<b>", ""), "</b>", "") cell.Value = str cell.Characters(nBold, nChars).Font.Bold = True End If Next cell End Sub
看看这个链接了解更多信息。