将文本从 Excel 单元格输入到 Word 并保留格式
我有以下代码,
strMyFormat1 = oWB.Worksheets(strSelectedSheet).Range(strStemLocation).NumberFormat
WordApp.Selection.TypeText Format(oWB.Worksheets(strSelectedSheet).Range(strStemLocation), strMyFormat1) & vbCr
但它不保留 Excel 单元格的格式
,例如,如果 Excel 单元格为粗体,我希望在输入我的 Word 文档时保留该格式,
我知道它适用于复制和粘贴,但我不想这样做
I have the fllowing code
strMyFormat1 = oWB.Worksheets(strSelectedSheet).Range(strStemLocation).NumberFormat
WordApp.Selection.TypeText Format(oWB.Worksheets(strSelectedSheet).Range(strStemLocation), strMyFormat1) & vbCr
But it does not retain the format of the Excel Cell
e.g. if the Excel Cell is bold I want that to be retained when entering into my word doc
I know it works with copy and paste but I dont want to do that
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
单元格格式化有很多部分,但这里有一些可以帮助您入门:
注意:使用范围对象的
Text
属性来获取格式化版本;使用Value
获取未格式化的版本。另请注意,范围对象 (rng
) 应该是单个单元格。There are many parts to cell formatting, but here are a few to get you started:
Note: use the
Text
property of the range object to get the formatted version; useValue
to get the unformatted version. Also note that the range object (rng
) should be a single cell.此示例过程创建一个新的 Word 文档,并添加活动 Excel 工作表中每个单元格的内容,并保留(部分)格式:
This sample procedure creates a new Word document and adds the contents of each cell in the active Excel worksheet, keeping (some of) the formatting:
那么您有一个单元格,并且想要将其内容复制到 Word 文档中?
我会这样做:
这将完全复制文本,因为它原来是..字体,粗体,颜色等。
提醒:
单元格 = Excel 电子表格中的单元格
.Cell = 您想要粘贴到 Word 文档中的单元格
但是假设您想要将字体修改为 Arial 以更好地匹配 WordDoc 的其余部分,但仍然保留原始颜色和粗体等(如果存在)。只需添加
:可以对任何其他字体属性(如大小等)执行相同的操作
关键是在将其复制到 Word 文档后进行这些更改。
希望这可以帮助别人。
-S
So you have a cell and you want to copy its contents into a word Doc?
I'd do:
This will copy the text EXACTLY as it was originally.. font, bold, color etc.
Reminder:
Cell = the cell in the Excel spreadsheet
.Cell = the cell you want to paste into in the Word document
But say you want to modify the font to Arial to better match the rest of your WordDoc but still leave the original colors and bold etc IF any exists.. just add:
You can do the same for any of the other Font attributes like size etc
The key is making these changes AFTER it's copied into the Word doc.
Hope this helps someone out.
-S