My Excel Project(2) GaoFeng

gaofengld 2013-06-01 10:37:28
FileModel---------------------------------------------------------------------------

Public Function OpenExcelFile(filePath As Variant, visible As Boolean) As Excel.Workbook

Dim excelApp As Excel.Application

Dim excelBook As Excel.Workbook

Set excelApp = New Excel.Application

excelApp.visible = visible

filePath = DeleteLinefeed(filePath)

Set excelBook = excelApp.Workbooks.Open(filePath)

Set OpenExcelFile = excelBook

End Function

Public Function CloseExcelFile(ByRef excelBook As Excel.Workbook)

Dim excelApp As Excel.Application

Set excelApp = excelBook.Application

excelBook.Close savechanges:=True

Set excelBook = Nothing

excelApp.Quit

Set excelApp = Nothing

End Function

Public Function OpenExcelDialog() As Variant

Dim fileOpen As Variant

fileOpen = Application.GetOpenFilename("Microsoft Excel(*.xls;*.xlsx;*.xlsm),*.xls;*.xlsx;*.xlsm", multiSelect:=True)

If Not IsArray(fileOpen) Then

ReDim fileOpen(1 To 1)

End If

OpenExcelDialog = fileOpen

End Function

Public Function OpenFileDialog(openType As Integer, multiSelect As Boolean) As Variant

Dim dlgOpen As FileDialog

Dim fileNum As Long

Dim filePathArray As Variant

Set dlgOpen = Application.FileDialog(openType)

With dlgOpen

.AllowMultiSelect = multiSelect

.Filters.Clear

.Filters.Add "Excel Files", "*.xlsx;*.xls"

.Filters.Add "All Files", "*.*"

If .Show = -1 Then

ReDim filePathArray(1 To .SelectedItems.Count)

For fileNum = LBound(filePathArray) To UBound(filePathArray)

filePathArray(fileNum) = .SelectedItems(fileNum)

Next fileNum

Else

ReDim filePathArray(1 To 1)

End If

End With

OpenFileDialog = filePathArray

Set dlgOpen = Nothing

End Function

Public Function GetUsedRangeValues(ByRef myWorkbook As Excel.Workbook) As Variant

Dim myWorksheets As Variant

Dim myWorksheet As Excel.Worksheet

Dim i As Long

Dim j As Long

Dim k As Long

Dim resultArray As Variant

Dim startRow As Integer

Dim startColumn As Integer

Dim endRow As Integer

Dim endColumn As Integer

Dim myRange As Excel.Range

Dim value As String

Set myWorksheets = myWorkbook.worksheets

For Each myWorksheet In myWorksheets

With myWorksheet

startRow = .UsedRange.row

startColumn = .UsedRange.column

endRow = .UsedRange.row + .UsedRange.Rows.Count - 1

endColumn = .UsedRange.column + .UsedRange.Columns.Count - 1

For i = startRow To endRow

For j = startColumn To endColumn

Set myRange = .Cells(i, j)

value = myRange.value

If IsNotNull(value) Then

k = k + 1

Call AppendDimArray(resultArray, myWorkbook.Path & "\" & myWorkbook.Name, k, 1)

Call AppendDimArray(resultArray, .Name, k, 2)

Call AppendDimArray(resultArray, i, k, 3)

Call AppendDimArray(resultArray, j, k, 4)

Call AppendDimArray(resultArray, myRange.value, k, 5)

End If

Set myRange = Nothing

Next j

Next i

End With

Next

Set myWorksheets = Nothing

GetUsedRangeValues = resultArray

End Function

Public Function GetFilePathValues(filePath As Variant) As Variant

Dim myWorkbook As Excel.Workbook

Dim resultValueTmp As Variant

Dim resultValue As Variant

Dim i As Integer

For i = LBound(filePath) To UBound(filePath)

Set myWorkbook = OpenExcelFile(filePath(i), False)

resultValueTmp = GetUsedRangeValues(myWorkbook)

Call AppendLinesOFArray(resultValue, resultValueTmp)

Set resultValueTmp = Nothing

Call CloseExcelFile(myWorkbook)

Next i

GetFilePathValues = resultValue

End Function


FileModel---------------------------------------------------------------------------

...全文
195 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
内容概要:本文提出一种基于鱼鹰优化算法(OOA)优化的CNN-BiGUR-Attention混合模型,用于提升短期风电功率预测的精度与稳定性,采用Matlab实现代码仿真。该模型融合卷积神经网络(CNN)提取输入数据的局部空间特征,利用双向门控循环单元(BiGUR)捕捉风速、功率等时间序列的前后向动态依赖关系,并引入注意力机制自适应强化关键时间步的特征权重,从而增强模型对非平稳风电数据的表征能力;进一步,采用OOA算法对模型超参数进行全局寻优,有效提升模型收敛速度与泛化性能。研究基于实际风电场历史数据开展实验验证,结果表明,该方法相较传统模型在预测精度、鲁棒性和误差抑制方面表现更优,适用于高比例可再生能源接入背景下的电力系统调度需求。; 适合人群:从事新能源发电预测、电力系统优化调度、智能算法与深度学习融合应用等方向的科研人员及工程技术人员,尤其适合具备Matlab编程能力、熟悉时间序列建模与深度学习框架的研究者。; 使用场景及目标:①实现风电场短期功率高精度预测,支撑电网安全稳定调度与能量管理;②为深度学习模型结构设计与智能优化算法联合调参提供实践范例;③推动人工智能技术在可再生能源预测、智能电网运行等领域的落地应用。; 阅读建议:建议结合提供的Matlab代码深入理解CNN-BiGUR-Attention网络架构搭建、注意力机制实现方式及OOA优化流程,重点关注数据预处理、模型训练与参数调优细节,可通过替换不同风电数据集进行对比实验,进一步掌握模型迁移能力与适应性。

25,980

社区成员

发帖
与我相关
我的任务
社区描述
高性能WEB开发
社区管理员
  • 高性能WEB开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧