gpt4 book ai didi

excel - 在 Excel 中所有单元格的开头插入文本

转载 作者:行者123 更新时间:2023-12-04 21:54:10 24 4
gpt4 key购买 nike

我有一个 excel 文件,其中有一个用数值填充的 A 列,我想将文本“dt”添加到数值之前的值中。当然,文本 dt 将被添加到存在值的整个列中。不幸的是,我的代码中的某些内容不起作用

Imports System
Imports System.IO
Imports Excel
Imports System.IO.FileStream
Imports Microsoft.Office.Interop.Excel


Public Class Form1

Private Sub Button5_Click_1(sender As Object, e As EventArgs) Handles Button5.Click

Dim oExcel As New Microsoft.Office.Interop.Excel.Application

Dim oBook As Microsoft.Office.Interop.Excel.Workbook

Dim oSheet As Microsoft.Office.Interop.Excel.Worksheet

oBook = oExcel.Workbooks.Open("C:\Users\PC\Desktop\1.xlsx")

oSheet = oBook.Worksheets(1)


Dim rg21 = oSheet.Columns("A:A")

rg21.Select()
rg21.NumberFormat = "@"

rg21 = "dt" & rg21

oBook.Save()

oExcel.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)

System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)

oBook = Nothing

oExcel = Nothing


End Sub
End Class

最佳答案

我会使用 循环 .在 Excel VBA 中:

Sub dural()
Dim r As Range
Set r = Columns(1).Cells.SpecialCells(2)
For Each rr In r
rr.Value = "dt" & rr.Value
Next rr
End Sub

将此适应 VB.Net。

关于excel - 在 Excel 中所有单元格的开头插入文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48140409/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com