当前位置: 首页 > wzjs >正文

网站后台数据处理编辑主要是做什么的啊wordpress做成淘宝客

网站后台数据处理编辑主要是做什么的啊,wordpress做成淘宝客,网站规划的特点,做网页的app(VBA实现Excel转csv) 初步学习了VBA相关的知识后,解决了一个需求: 要求读取指定xlsx文件中的指定sheet页,将该sheet页的内容转换为csv文件。 实现的布局如下所示: 文章目录 ①实现从指定行开始全数据转换为…

(VBA实现Excel转csv)
初步学习了VBA相关的知识后,解决了一个需求:
要求读取指定xlsx文件中的指定sheet页,将该sheet页的内容转换为csv文件。
实现的布局如下所示:
在这里插入图片描述

文章目录

  • ①实现从指定行开始全数据转换为csv
  • ②实现指定行指定列部分数据转换为csv

①实现从指定行开始全数据转换为csv

1、Select-File 按钮功能实现
Select-File 按钮主要是实现选取文件,并将选取文件路径显示到下方。

Private Sub CommandButton1_Click()Dim filePath As StringfilePath = SelectFile()If filePath <> "" ThenTextBox1.Text = filePathElseTextBox1.Text = "Please select file丅"End If
End SubPublic Function SelectFile(Optional title As String = "Select File") As StringWith Application.FileDialog(msoFileDialogFilePicker).title = title.AllowMultiSelect = False.Filters.Clear.Filters.Add "all file", "*.*"If .Show = -1 ThenSelectFile = .SelectedItems(1)ElseSelectFile = ""End IfEnd With
End Function

2、Output-File 按钮功能实现
Output-File 按钮功能:读取选取文件的指定sheet页,将对应内容转换为csv文件进行保存,并将保存文件的路径显示在下方。

Private Sub CommandButton3_Click()On Error GoTo ErrorHandlerDim sourceFilePath As StringDim wbSource As WorkbookDim wsSource As WorksheetDim savePath As StringDim fso As ObjectDim ts As ObjectDim lastRow As Long, lastCol As LongDim i As Long, j As LongDim csvContent As StringDim dataArr() As VariantDim startRow As LongDim fileName As String, folderPath As StringDim timeStamp As StringDim targetCols As VariantDim colIndex As VariantDim colCounter As LongDim tempArr As VariantDim rowData As VarianttargetCols = Array(1, 3, 5, 6, 7)Dim colCount As LongcolCount = UBound(targetCols) - LBound(targetCols) + 1startRow = 4sourceFilePath = Trim(TextBox1.Text)If sourceFilePath = "" ThenMsgBox "Please select the file丅", vbExclamationExit SubEnd IfIf Dir(sourceFilePath) = "" ThenMsgBox "File does not exit, please select again", vbCriticalExit SubEnd IfSet fso = CreateObject("Scripting.FileSystemObject")fileName = "Test11111.csv"fileExt = fso.GetExtensionName(sourceFilePath)folderPath = fso.GetParentFolderName(sourceFilePath)savePath = folderPath & "\" & fileNameTextBox2.Text = savePathIf Dir(savePath) <> "" ThenIf MsgBox("The file already exists, do you want to overwrite it?", vbQuestion + vbYesNo) = vbNo ThenExit SubEnd IfEnd IfApplication.ScreenUpdating = FalseSet wbSource = Workbooks.Open(sourceFilePath, ReadOnly:=True)Set wsSource = wbSource.Sheets("Sheet1")With wsSourcelastRow = .Cells(.Rows.Count, 1).End(xlUp).RowactualLastCol = .Cells(startRow, .Columns.Count).End(xlToLeft).ColumnmaxCol = Application.Max(targetCols)If lastRow < startRow ThenMsgBox "Data does not exits丅", vbExclamationGoTo CleanUpEnd IftempArr = .Range(.Cells(startRow, 1), .Cells(lastRow, maxCol)).ValueDim rowCount As LongrowCount = UBound(tempArr, 1)ReDim dataArr(1 To rowCount, 1 To colCount)For i = 1 To rowCountcolCounter = 1For Each colIndex In targetColsIf colIndex <= UBound(tempArr, 2) ThendataArr(i, colCounter) = tempArr(i, colIndex)ElsedataArr(i, colCounter) = ""End IfcolCounter = colCounter + 1Next colIndexNext iEnd WithSet ts = fso.CreateTextFile(savePath, True, False)For i = 1 To UBound(dataArr, 1)csvContent = ""For j = 1 To UBound(dataArr, 2)csvContent = csvContent & CleanCSVValue(dataArr(i, j))If j < UBound(dataArr, 2) Then csvContent = csvContent & ","Next jts.WriteLine csvContentNext its.CloseMsgBox "CSV file:" & vbCrLf & savePath, vbInformation, "has outputed"
CleanUp:If Not wbSource Is Nothing ThenwbSource.Close SaveChanges:=FalseSet wbSource = NothingEnd IfSet ts = NothingSet fso = NothingSet wsSource = NothingApplication.ScreenUpdating = TrueExit SubErrorHandler:MsgBox "Error happend" & Err.Description, vbCritical, "ERROR"Resume CleanUp
End Sub
Private Function CleanCSVValue(ByVal inputValue As Variant) As StringIf IsEmpty(inputValue) Or IsNull(inputValue) ThenCleanCSVValue = ""Exit FunctionEnd IfDim result As Stringresult = CStr(inputValue)If InStr(result, ",") > 0 Or InStr(result, """") > 0 Or InStr(result, vbCr) > 0 Or InStr(result, vbLf) > 0 Thenresult = Replace(result, """", """""")result = """" & result & """"End IfCleanCSVValue = result
End Function

3、Clear 按钮功能实现
Clear 按钮主要是将下方两个文件路径清空。

Private Sub CommandButton2_Click()TextBox1.Text = ""TextBox2.Text = ""
End Sub

实现的效果如图所示:
在这里插入图片描述

②实现指定行指定列部分数据转换为csv

1、Select-File 按钮功能实现
3、Clear 按钮功能实现
这两个按钮的实现和①一致,没有区别,关键不同点在于转换部分。
2、Output-File 按钮功能实现
Output-File 按钮功能:读取选取文件的指定sheet页,将 指定的列对应内容转换为csv文件进行保存,并将保存文件的路径显示在下方。

Private Sub CommandButton3_Click()On Error GoTo ErrorHandlerDim sourceFilePath As StringDim wbSource As WorkbookDim wsSource As WorksheetDim savePath As StringDim fso As ObjectDim ts As ObjectDim lastRow As Long, lastCol As LongDim i As Long, j As LongDim csvContent As StringDim dataArr() As VariantDim startRow As LongDim fileName As String, folderPath As StringDim timeStamp As StringDim targetCols As VariantDim colIndex As VariantDim colCounter As LongDim tempArr As VariantDim rowData As VarianttargetCols = Array(1, 3, 5, 6, 7)Dim colCount As LongcolCount = UBound(targetCols) - LBound(targetCols) + 1startRow = 4sourceFilePath = Trim(TextBox1.Text)If sourceFilePath = "" ThenMsgBox "请选择文件。", vbExclamationExit SubEnd IfIf Dir(sourceFilePath) = "" ThenMsgBox "文件不存在,请重新选择。", vbCriticalExit SubEnd IfSet fso = CreateObject("Scripting.FileSystemObject")fileName = "11111.csv"fileExt = fso.GetExtensionName(sourceFilePath)folderPath = fso.GetParentFolderName(sourceFilePath)savePath = folderPath & "\" & fileNameTextBox2.Text = savePathIf Dir(savePath) <> "" ThenIf MsgBox("文件已存在,是否覆盖", vbQuestion + vbYesNo) = vbNo ThenExit SubEnd IfEnd IfApplication.ScreenUpdating = FalseSet wbSource = Workbooks.Open(sourceFilePath, ReadOnly:=True)Set wsSource = wbSource.Sheets("Sheet1")With wsSourcelastRow = .Cells(.Rows.Count, 1).End(xlUp).RowactualLastCol = .Cells(startRow, .Columns.Count).End(xlToLeft).ColumnmaxCol = Application.Max(targetCols)If lastRow < startRow ThenMsgBox "文件没有数据", vbExclamationGoTo CleanUpEnd IftempArr = .Range(.Cells(startRow, 1), .Cells(lastRow, maxCol)).ValueDim rowCount As LongrowCount = UBound(tempArr, 1)ReDim dataArr(1 To rowCount, 1 To colCount)For i = 1 To rowCountcolCounter = 1For Each colIndex In targetColsIf colIndex <= UBound(tempArr, 2) ThendataArr(i, colCounter) = tempArr(i, colIndex)ElsedataArr(i, colCounter) = ""End IfcolCounter = colCounter + 1Next colIndexNext iEnd WithSet ts = fso.CreateTextFile(savePath, True, False)For i = 1 To UBound(dataArr, 1)csvContent = ""For j = 1 To UBound(dataArr, 2)csvContent = csvContent & CleanCSVValue(dataArr(i, j))If j < UBound(dataArr, 2) Then csvContent = csvContent & ","Next jts.WriteLine csvContentNext its.CloseMsgBox "CSV文件:" & vbCrLf & savePath, vbInformation, "转换完成"
CleanUp:If Not wbSource Is Nothing ThenwbSource.Close SaveChanges:=FalseSet wbSource = NothingEnd IfSet ts = NothingSet fso = NothingSet wsSource = NothingApplication.ScreenUpdating = TrueExit SubErrorHandler:MsgBox "错误发生" & Err.Description, vbCritical, "ERROR"Resume CleanUp
End Sub
Private Function CleanCSVValue(ByVal inputValue As Variant) As StringIf IsEmpty(inputValue) Or IsNull(inputValue) ThenCleanCSVValue = ""Exit FunctionEnd IfDim result As Stringresult = CStr(inputValue)If InStr(result, ",") > 0 Or InStr(result, """") > 0 Or InStr(result, vbCr) > 0 Or InStr(result, vbLf) > 0 Thenresult = Replace(result, """", """""")result = """" & result & """"End IfCleanCSVValue = result
End Function

文章转载自:

http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://00000000.qnLbb.cn
http://www.dtcms.com/wzjs/598658.html

相关文章:

  • 住房和城乡建设部网站共有产权建设网站公司兴田德润官方地址
  • 做一个网站要多长时间长沙网站建设优化
  • 广安哪里有做网站的公司网站主要盈利模式
  • 建设企业网站管理系统目的黑龙江省住房和城乡建设厅官网
  • 泡沫制品技术支持东莞网站建设网站seo搜索引擎优化案例
  • 网站建设需要这些工具和软件公司网站怎么做才能吸引人
  • 网站建设服务费是否无形资产河池网站制作
  • 金昌市建设局网站自己做的网站添加交费功能
  • 263网站建设怎么样线上广告
  • 网站购买云空间网站cms系统哪个好用吗
  • 加强企业网站建设的通知新闻摘抄大全
  • 优质网站建设公司哪家好有一个做场景动画的网站
  • 重庆网站推广运营建一个app平台的费用多少
  • 有电脑网站怎么做手机网站wordpress网站建设
  • 牡丹江住房和城乡建设厅网站安卓系统app
  • 江苏优化网站价格网站ftp上传到空间
  • 国外网站建立网站功能的介绍
  • 业务推广网站个人网站设计论文php
  • 网站源码商城域名注册管理机构
  • 开发网站建设方案唐山住房和城乡建设厅网站
  • 在企业网站建设的解决方案中购物app排行
  • 盈利网站城市门户网站策划书
  • 多个域名多国语言网站seo优化多少关键词排名优化软件
  • 专业店面店铺装修设计网络优化app哪个好
  • 学做实体店网站做网站需要什么技能
  • 临泉网站建设视频制作软件教程
  • 优秀的个人博客网站网站做多长时间才会有流量
  • 网站制作包括什么大气网站图
  • 如何帮网站上海哪家公司提供专业的网站建设
  • 北京网站优化多少钱利用腾讯云建设网站