VB.NET EXCEL(函数操作,求和,平均值)
2020-04-20 15:47
731 查看
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Dim xlApp As Object = Nothing Dim xlBooks As Microsoft.Office.Interop.Excel.Workbooks = Nothing Dim xlBook As Microsoft.Office.Interop.Excel.Workbook = Nothing Dim xlSheets As Microsoft.Office.Interop.Excel.Sheets = Nothing Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet = Nothing Dim myrange As Microsoft.Office.Interop.Excel.Range = Nothing ' Dim strFilePath As String = "C:\Users\18608\Desktop\text.xlsx" xlApp = New Microsoft.Office.Interop.Excel.Application() xlBooks = xlApp.Workbooks xlBook = xlBooks.Open("C:\Users\18608\Desktop\text.xlsx") xlSheets = xlBook.Worksheets xlSheet = xlSheets("Sheet1") '这里是你要读入数据的那个sheet页 TextBox2.Text = xlSheet.UsedRange.Columns.Count '获取Excel有效区域列数 rows1 = xlSheet.UsedRange.Rows.Count '获取Excel有效区域的行数 TextBox1.Text = xlSheets.Application.WorksheetFunction.Sum(xlSheet.Range("c1:c1000")) '利用sum函数 求和 xlBook.Close(True) '关闭工作簿 xlApp.Quit '结束EXCEL对象 End Sub
条件求和
https://zhidao.baidu.com/question/429596474.html
1、示例代码:
Sub test1()
Dim x As Long
x = WorksheetFunction.SumIf(Range(“A2:A9”), Range(“C2”).Value, Range(“B2:B9”))
Range(“D2”).Value = x
End Sub
2、如下图:
3、以上代码的作用是:调用工作表函数SUMIF,求A2:A9范围内符合C2单元格条件,对应的B2:B9范围内数值之和,结果输出到D2单元格。
jshe = xlSheets.Application.WorksheetFunction.SumIf(xlSheet.Range("g2:g" & rows1), xlSheet.Range("h2"), xlSheet.Range("c2:c" & rows1)) '求和 TextBox1.Text = xlSheet.Range("h2").Value MsgBox(jshe)
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- vb.net操作excel时,如何判断单元格内容为空
- vb.net 操作excel
- VB.NET使用EXCEL常见操作
- VB.Net操作Excel
- vb.net office excel 和wps共存,创建正确的excel对象以便操作excel表格
- VB.net中字符串操作函数
- VB.NET中字符串操作函数
- VB.NET使用EXCEL常见操作
- VB.NET操作EXCEL的代码
- ASP.NET环境下,VB.NET语言,数据保存EXCEL模板操作
- 通过vb.net 和NPOI实现对excel的读操作
- 这么详细的分类 VB/VB.NET源代码网站你见过没有? VB/VB.NET中的每一个方法,每一个操作,每一个函数,每一个类.每一个属性,每一个事件都有相应的范例代码
- vb.net中字符串操作函数(转)
- vb.net操作EXCEL
- ASP.NET环境下,VB.NET语言,数据保存EXCEL模板操作
- Word表格也可以像Excel表格一样使用求和等函数,不用操作计算器了
- [VB.NET源码]读写Excel的操作应用
- vb.net对excel的操作------感谢:就爱小毛虫
- VB.NET使用EXCEL常见操作
- [VB.NET]关于vb.net操作Excel发生