excel - 从 Excel 电子表格中提取信息
问题描述
我目前正在尝试创建一个程序来从 Excel 电子表格中提取信息,不幸的是我在这场战斗中没有一只狗,哈哈。所以无论如何,我基本上都会做报价和估计,并且我已经设置了 Excel,我只需要将特定信息从单个单元格中提取为“100 美元/英尺”格式。相反,我得到 100.3216 ....... 另外,我正在寻找一种方法来仅使用短键来生成和重置标签框值而不是多个按钮。
这是我到目前为止所拥有的......
Private Sub GetQuote_Click()
Dim objExcel As New Excel.Application
Dim exWb As Excel.Workbook
Set exWb = objExcel.Workbooks.Open("C:\Users\tcreel\Documents\quoteautofill.xlsx")
ThisDocument.Label1.Caption = "Horizontal Straight Housing & Cable " & _
exWb.Sheets("Quote Sheet").Cells(7, "O") 'horizontal footage price'
ThisDocument.Label2.Caption = "Vertical Straight Housing & Cable " & _
exWb.Sheets("Quote Sheet").Cells(8, "O") 'verticle footage price'
ThisDocument.Label3.Caption = "Horizontal 90-degree Elbow & Cable " & _
exWb.Sheets("Quote Sheet").Cells(9, "O") ' hor.90° elbow price'
ThisDocument.Label4.Caption = "Vertical 90-degree Elbow & Cable " & _
exWb.Sheets("Quote Sheet").Cells(10, "O") 'vert. 90° price'
exWb.Close
Set exWb = Nothing
End Sub
解决方案
您应该使用如下代码:
exWb.Sheets("Quote Sheet").Cells(7, "O").Text
(如果您的工作簿以所需的输出格式显示内容),或者:
Format(exWb.Sheets("Quote Sheet").Cells(7, "O").Value, "$#,##0.00")
其中 "$#,##0.00" 指定所需的输出格式。
推荐阅读
- docker - 如何删除损坏的 docker 容器中的文件?
- python - 将 pandas df 导出到 SAS xpt(xport 模块):日期转换为字符串
- gitlab - 如何在 Gitlab 中的组内创建不同的项目
- r - 在 RStudio 中将非结构化日志文件作为文本文件读取
- gitlab-ci - 如何为 Gitlab 管道自动生成 GPG 密钥对
- windows - 如何在 Windows 10 上将 DPI 比例设置为小于 100% - 使用多个显示器
- css - 如何使用 CSS 合并和填充两个圆圈中的颜色
- r - 将新数据插入表中
- postgresql - Postgres - 使用 unnest 是否可以查询未嵌套的每行?
- javascript - 在css中的下一行重叠悬停弹出窗口