十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
将二位数组转成DataTable,网上找的不知道成不成
创新互联服务项目包括颍上网站建设、颍上网站制作、颍上网页制作以及颍上网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,颍上网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到颍上省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
public static DataTable ConvertToDataTable(string[,] arr)
{
DataTable dataSouce = new DataTable();
for (int i = 0; i arr.GetLength(1); i++)
{
DataColumn newColumn = new DataColumn(i.ToString(), arr[0, 0].GetType());
dataSouce.Columns.Add(newColumn);
}
for (int i = 0; i arr.GetLength(0); i++)
{
DataRow newRow = dataSouce.NewRow();
for (int j = 0; j arr.GetLength(1); j++)
{
newRow[j.ToString()] = arr[i, j];
}
dataSouce.Rows.Add(newRow);
}
return dataSouce;
}
Dim i As Integer, j As Integer, X As Single, Y As Single, M As Single
i = L
j = R
'找出数组的中点
M = MyArray((L + R) / 2, 0)
While (i = j)
'找出比中点大的数
While (MyArray(i, 0) M And i R)
i = i + 1
Wend
'找出比中点小的数
While (M MyArray(j, 0) And j L)
j = j - 1
Wend
'互换这两个数
If (i = j) Then
X = MyArray(i, 0)
Y = MyArray(i, 1)
MyArray(i, 0) = MyArray(j, 0)
MyArray(i, 1) = MyArray(j, 1)
MyArray(j, 0) = X
MyArray(j, 1) = Y
i = i + 1
j = j - 1
End If
Wend
'未完成时递归调用
If (L j) Then Call QuickSort(MyArray(), L, j)
If (i R) Then Call QuickSort(MyArray(), i, R)
End Sub
这个比较简单
假如二维数组是str(row,col)
假设Workbook是Excel的工作簿对象
Workbook.worksheets(1).range("A2").Resize(row+1, col+1).Value = str
其中关键的是Excel的Resize方法能快速的插入二维数组
Dim rootlist() As String
Dim data(0, 0) As String
Dim tmp() As String
Dim listLengh As Int32
Dim I As Integer, II As Integer
rootlist = Split(IO.File.OpenText("C:/001.txt").ReadToEnd, vbCrLf)
listLengh = UBound(rootlist)
ReDim data(listLengh, 0)
For I = 0 To listLengh
tmp = Split(rootlist(I), ",")
ReDim Preserve data(listLengh, UBound(tmp))
For II = 0 To UBound(tmp)
data(I, II) = tmp(II)
Next
Next
For I = 0 To 2
For II = 0 To 2
MsgBox(data(I, II))
Next
Next
根据你的语句,上下标是确定的,所以定义语句修改为:
Dim ary(UBound(temp), 1) As String '声明二维数组