主页 > 办公自动化 > d3能不能读取excel?

d3能不能读取excel?

2022-10-17 01:33来源:m.sf1369.com作者:宇宇

可以。

需要添加如下引用:

System.Configuration

System.Data

System.EnterpriseServices

System.Security

System.XML

using UnityEngine;

using System.Collections;

using System;

using System.Data;

using System.Data.Odbc;

public class EXCELREADER : MonoBehaviour {

DataTable dtYourData = new DataTable(YourData);

string str = ;

// Use this for initialization

void Start () {

readXLS(Application.dataPath + /Book1.xls);

str = +dtYourData.Rows[2][dtYourData.Columns[2].ColumnName].ToString();

}

// Update is called once per frame

void Update () {

}

void OnGUI(){

GUILayout.Label(str);

}

void readXLS( string filetoread)

{

// Must be saved as excel 2003 workbook, not 2007, mono issue really

string con = Driver={Microsoft Excel Driver (*.xls)}; DriverId=790; Dbq=+filetoread+;;

Debug.Log(con);

string yourQuery = SELECT * FROM [Sheet1$];

// our odbc connector

OdbcConnection oCon = new OdbcConnection(con);

// our command object

OdbcCommand oCmd = new OdbcCommand(yourQuery, oCon);

// table to hold the data

// open the connection

oCon.Open();

// lets use a datareader to fill that table!

OdbcDataReader rData = oCmd.ExecuteReader();

// now lets blast that into the table by sheer man power!

dtYourData.Load(rData);

// close that reader!

rData.Close();

// close your connection to the spreadsheet!

oCon.Close();

// wow look at us go now! we are on a roll!!!!!

// lets now see if our table has the spreadsheet data in it, shall we?

if(dtYourData.Rows.Count > 0)

{

// do something with the data here

// but how do I do this you ask??? good question!

for (int i = 0; i < dtYourData.Rows.Count; i++)

{

// for giggles, lets see the column name then the data for that column!

Debug.Log(dtYourData.Columns[0].ColumnName + : + dtYourData.Rows[i][dtYourData.Columns[0].ColumnName].ToString());

}

}

}

}

相关推荐

企业办公软件都有哪些?

办公自动化 2024-01-14

数控车床自动编程用什么软件?

办公自动化 2024-01-12

写字间物业管理方案

办公自动化 2023-12-09

自动化的好处和坏处

办公自动化 2023-12-05

单片机有什么特征?

办公自动化 2023-11-27

excel2007教程|excel2007教程下载

办公自动化 2023-11-22