如何将大(最多10Mb)大文本文件嵌入Excel文件 [英] How to embed large (max 10Mb) text files into an Excel file

查看:340
本文介绍了如何将大(最多10Mb)大文本文件嵌入Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Excel文件中存储大文本文件(最大10Mb)的最佳方式是什么?

What is the best way to store a large text file (max 10Mb) in an Excel file?

我有几个要求:


  1. 嵌入,以便将Excel文件移动并发送到不同的计算机,所有的文本文件都将遵循。

  1. It has to be embedded so that the excel file can be moved and sent to a different computer and all the text files will follow.

需要从宏

宏嵌入后需要能够读取文件内容。

And a macro needs to be able to read the file contents after it has been embedded.

我已经尝试通过将文本分解成几个小到适合单元格(〜32 000个字符)的块来存储,但它没有起作用。在我的宏插入前150000个字符后,它给了我一个内存不足错误。

I already tried to store it by breaking the text into several chunks enough small to fit into a cell (~32 000 chars), but it didn't work. After my macro had inserted the first 150 000 characters it gave me an "Out of Memory" error.

我记得看到一个网页有几个选项,这个我但是找不到它了。任何建议都是最受欢迎的。

I remember seeing one web page with a couple of options for this I but cannot find it anymore. Any suggestions are most welcome. I will try them out if you are not sure if it works or not.

推荐答案

非常简单的CustomXMLPart示例:

Very simple CustomXMLPart example:

Sub CustomTextTester()

    Dim cxp1 As CustomXMLPart, cxp2 As CustomXMLPart
    Dim txt As String

    'read file content
    txt = CreateObject("scripting.filesystemobject").opentextfile( _
                                      "C:\_Stuff\test.txt").readall()

    'Add a custom XML part with that content
    Set cxp1 = ThisWorkbook.CustomXMLParts.Add("<myXMLPart><content><![CDATA[" & txt _
                                               & "]]></content></myXMLPart>")

    Debug.Print cxp1.SelectSingleNode("myXMLPart/content").FirstChild.NodeValue

End Sub

这篇关于如何将大(最多10Mb)大文本文件嵌入Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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