如何使 Excel 标签标题中的文本垂直居中?
在 Excel 2007 中,我将 ActiveX 标签插入到工作表中。我右键单击它并查看“属性”,并设法将 TextAlign 属性更改为 2 (frmTextAlignCenter)。
这会将标签标题的文本与标签的中心(水平)对齐,但文本仍保留在标签的顶部。如何将标题文本垂直居中,使其位于标签的正中间?
我在 SO 中搜索了“垂直对齐”,但没有找到如何对 Excel 标签的标题执行此操作的信息。
In Excel 2007, I inserted an ActiveX label onto my worksheet. I right-clicked on it and viewed Properties and managed to change the TextAlign property to 2 (frmTextAlignCenter).
This aligns the label caption's text to the center of the label (horizontally), but the text remains at the TOP of the label. How do I center the caption's text VERTICALLY so that it is in the smack middle of the label?
I've searched "vertical alignment" in SO but nothing comes up for how to do this for an Excel label's caption.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
有一个技巧可以用单个标签来做到这一点。
添加 1x1 像素的透明 gif 图像(此处)并将 PictureAlignment 属性设置为 PicturePositionLeftCenter。
There is a trick to do it with a single label.
Add an transparent gif image of 1x1 pixel (here) and set the PictureAlignment property to PicturePositionLeftCenter.
没有办法直接做到这一点。 这篇文章有一个聪明的方法来完成它, 尽管。制作 2 个框,其中内部框围绕文本自动调整大小,并将内部框放置在外部框的中点。
There's no way to do it directly. This post has a clever way to accomplish it, though. Make 2 boxes, with the inner one autosized around the text, and position that inner box at the midpoint of the outer box.
我刚刚尝试了投票最高的答案中概述的方法,效果非常好。不过,要在方法中添加一些内容 - 例如,如果您有很多标签,我会执行以下操作:
GIF
False
"LabelAlignmentTheme"
UserForm_Initialize
中添加以下代码我很喜欢
Tag
的这种用法,感觉就像是css样式。显然,您可以跳过对标签的检查(删除 And 语句的后半部分)并对齐所有内容,但我认为这是一个更现实的场景,您只需要一些对齐。通过将图像存储在表单中某处的共享隐藏图片中,它将嵌入到文件中。
I just tried the approach outlined in the top voted answer and it worked perfectly. To add a little to the approach though - if you have many labels for example, I did the following:
GIF
False
"LabelAlignmentTheme"
UserForm_Initialize
I like this use of
Tag
, it feels like a css style. Obviously you can skip the check for the tag (remove the second half of the And statement) and align absolutely everything but I think this is a more realistic scenario where you only want some aligned.By storing the image in a shared hidden picture somewhere in the form, it is embedded in the file.
您必须使用 2 个标签。
例如,将它们称为 LabelBack、LabelFront。 LabelFront应设置为不透明和无边框,使LabelFront的高度小于LabelBack的高度,并将其或多或少地放在它上面。
然后添加以下代码:
注意,我减去了
1
以补偿 LabelFront 内的1
额外像素。You will have to use 2 Labels.
For Example, Call them LabelBack, LabelFront. The LabelFront should be set to Opaque and No-Border Make the height of LabelFront smaller than that of LabelBack and put it over it more or less.
Then add the following code:
Notice, I subtracted
1
to compensate the1
extra pixel within the LabelFront.这看起来像(在课堂上):作者 TRUNG SON
代码在这里
This look like (in class): author TRUNG SON
ter code here
这看起来像(在模块中):作者 TRUNG SON
This look like (in module): author TRUNG SON