以编程方式左对齐 Excel 文档中的数字
如何在 VB 中以编程方式左对齐 Excel 中的列?我有一个 VB 程序,它根据某些信息编写 Excel 文件。我尝试过使用:
oSheet.Columns.HorizontalAlignment.Left()
这适用于带有文本的列。我有多个列,它们都是严格的数字。此函数不适用于具有数字单元格的列。
以下是我不断收到的 MissingMemberException:
Public member 'Left' on type 'Integer' not found.
How do I left justify my columns in Excel programmatically in VB? I have a VB program that is writing an excel file based off of certain information. I have tried using:
oSheet.Columns.HorizontalAlignment.Left()
This works against columns with text. I have multiple columns that are strictly numbers. This function will not work against columns with Numeric Cells.
Below is the MissingMemberException I keep getting:
Public member 'Left' on type 'Integer' not found.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Range.HorizontalAlignment 是一个需要整数常量的属性。左边是xlLeft。 xlLeft 的计算结果为 -4131。 xlDistributed 为 -4117,xlRight 为 -4152,xlCenter 为 -4108,xlJustify 为 -4130。
Range.HorizontalAlignment is a property that requires an integer constant. Left is xlLeft. xlLeft evaluates to -4131. xlDistributed is -4117, xlRight is -4152, xlCenter is -4108, and xlJustify is -4130.
HorizontalAlignment 应该适用于文本和数字。不过,您应该指定对齐的值,因为它是一个属性。
HorizontalAlignment should work for both text and numbers. You should specify the value for the alignment though since it is a property.
虽然 @Banjoe 答案可行,但文档< /a> 为 HorizontalAlignment 属性指定以下有效常量:
Although the @Banjoe answer will work, the documentation specifies the following valid constants for HorizontalAlignment property:
我使用了以下内容,它对我来说非常有效:
I used the following, and it worked great for me: