Dim worksheet As Excel.Worksheet = CType(workbook.Sheets(i + 1), Excel.Worksheet) worksheet.Name = result(i).Key & "钢网架" worksheet.Cells.VerticalAlignment = Excel.Constants.xlCenter worksheet.Cells.HorizontalAlignment = Excel.Constants.xlCenter worksheet.Cells.Font.Name = "宋体" worksheet.Cells.Font.Color = Color.Black '设置标题 Dim logoRange As Excel.Range = worksheet.Range(worksheet.Cells(1, 1), worksheet.Cells(1, 1)) '选取单元格 logoRange.Value2 = "深圳斯坦雷电气有限公司" logoRange.HorizontalAlignment = Excel.Constants.xlLeft logoRange.Font.Size = 14 logoRange.EntireRow.RowHeight = 18.75 '设置标题 Dim titleRange As Excel.Range = worksheet.Range(worksheet.Cells(2, 1), worksheet.Cells(2, 8)) '选取单元格 titleRange.Merge(True) '合并单元格 titleRange.Value2 = resultWorkshop(w).Key & "钢网放置架记录表" titleRange.Font.Size = 23 titleRange.Font.Bold = True titleRange.EntireRow.RowHeight = 32.25 '副标题 Dim tipRange1 As Excel.Range = worksheet.Range(worksheet.Cells(3, 1), worksheet.Cells(3, 4)) worksheet.Range("A3:D3").Merge(0) '合并单元格 tipRange1.Value2 = "第一层" tipRange1.Font.Size = 20 tipRange1.Font.Bold = True '副标题 Dim tipRange2 As Excel.Range = worksheet.Range(worksheet.Cells(3, 4), worksheet.Cells(3, 8)) worksheet.Range("E3:H3").Merge(0) '合并单元格 tipRange2.Value2 = "第二层" tipRange2.Font.Size = 20 tipRange2.Font.Bold = True '列标题 Dim headerStr As String() = {"序号", "机种名", "使用次数", "备注", "序号", "机种名", "使用次数", "备注"} For j = 0 To headerStr.Length - 1 worksheet.Cells(4, j + 1) = headerStr(j) worksheet.Range(worksheet.Cells(4, j + 1), worksheet.Cells(4, j + 1)).RowHeight = 29.25 Select Case j Case 0, 4 worksheet.Range(worksheet.Cells(4, j + 1), worksheet.Cells(4, j + 1)).ColumnWidth = 5.38 Case 1, 5 worksheet.Range(worksheet.Cells(4, j + 1), worksheet.Cells(4, j + 1)).ColumnWidth = 27 worksheet.Range(worksheet.Cells(4, j + 1), worksheet.Cells(4, j + 1)).EntireColumn.WrapText = True Case 2, 6 worksheet.Range(worksheet.Cells(4, j + 1), worksheet.Cells(4, j + 1)).ColumnWidth = 10.75 Case 3, 7 worksheet.Range(worksheet.Cells(4, j + 1), worksheet.Cells(4, j + 1)).ColumnWidth = 12.13 worksheet.Range(worksheet.Cells(4, j + 1), worksheet.Cells(4, j + 1)).EntireColumn.Font.Size = 10 worksheet.Range(worksheet.Cells(4, j + 1), worksheet.Cells(4, j + 1)).EntireColumn.WrapText = True End Select Next 保持原有逻辑进行优化,让代码有更好的可读性,可维护性,提高性能,并说明理由
时间: 2024-04-07 18:32:02 浏览: 136
Course_select.zip_Work It_chart_excel chart_worksheet
首先,建议将代码进行模块化,将不同的功能封装成独立的函数或模块,提高代码的可读性和可维护性。
其次,可以采用一些技巧来提高代码的性能,例如使用数组代替列表,使用StringBuilder代替字符串拼接等。
另外,建议使用常量代替魔法数字,使用枚举类型代替字符串常量,增加代码的可读性和可维护性。
最后,可以增加注释和文档说明,帮助其他开发人员理解代码的逻辑和用途。
阅读全文