原創(chuàng)|其它|編輯:郝浩|2012-10-12 15:22:04.000|閱讀 6537 次
概述:Aspose.Cells控件是一個(gè)功能非常強(qiáng)大的控件。由于Aspose.Cells控件的功能很多和我個(gè)人的時(shí)間關(guān)系,這都是我抽下班時(shí)間連困帶餓寫的,哎!...... 所以在此我只寫了指定讀一個(gè)單元格的數(shù)據(jù)(此代碼指定讀B3單元格的數(shù)據(jù)),要學(xué)習(xí)的同志請(qǐng)到慧都控件網(wǎng)上找相關(guān)的資料。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Aspose.Cells控件是一個(gè)功能非常強(qiáng)大的控件。由于Aspose.Cells控件的功能很多和我個(gè)人的時(shí)間關(guān)系,這都是我抽下班時(shí)間連困帶餓寫的,哎!...... 所以在此我只寫了指定讀一個(gè)單元格的數(shù)據(jù)(此代碼指定讀B3單元格的數(shù)據(jù)),要學(xué)習(xí)的同志請(qǐng)到慧都控件網(wǎng)上找相關(guān)的資料。
要想使用Aspose.Cells控件,必須先購買此控件,然后還要在工程中引用此控件和使用的文件中using namespace,因?yàn)镃#中的方法在同一個(gè)命名空間中才有權(quán)訪問。接下來編寫代碼:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Data.OleDb; using Aspose.Cells; namespace WindowsFormsApplication1 { public partial class Form1 : Form { /// <summary> /// 默認(rèn)構(gòu)造函數(shù).<br></br> /// 2009-04-13 YJ 定義函數(shù).<br></br> /// </summary> public Form1() { InitializeComponent(); //此處的students.xls文件在工程下Bin的程序集目錄下 string opnFileName = Application.StartupPath.Trim() + "\\students.xls"; if(!string.IsNullOrEmpty(opnFileName)) { Workbook tcWorkBook = new Workbook(); tcWorkBook.Open(opnFileName); Worksheets tcWorkSheets = tcWorkBook.Worksheets; Worksheet tcWorkSheet; Cells tcCells; //索引行號(hào) //int tcRow = 0; //索引列號(hào) //int tcColumn = 0; Range tcRange; string sExcelValue = ""; Cell tcCell; for (int i = 0; i < tcWorkSheets.Count; i++) { tcWorkSheet = tcWorkSheets[i]; tcCells = tcWorkSheet.Cells; //以索引的方式遍歷工作表 //tcCell = tcCells[tcRow, tcColumn]; tcCell = tcCells["a2"]; string tcSheetName = tcWorkSheets[i].Name; try { // sExcelValue = tcCell.Value.ToString(); sExcelValue = tcCell.StringValue; //可以獲取空值 MessageBox.Show("工作表 \"" + tcSheetName + "\" a2的數(shù)據(jù):" + sExcelValue); } catch (Exception ex) { MessageBox.Show("工作表 \"" + tcSheetName + "\" a2單元格不存在或者已經(jīng)被合并:" + ex.Message); } if (tcCell.IsMerged) { tcRange = tcCell.GetMergedRange(); MessageBox.Show("工作表 \"" + tcSheetName + "\" a2單元格合并了 " + tcRange.RowCount.ToString() + " 行。"); MessageBox.Show("工作表 \"" + tcSheetName + "\" a2單元格合并了 " + tcRange.ColumnCount.ToString() + " 列。"); } else { MessageBox.Show("工作表 \"" + tcSheetName + "\" a2單元格沒有被合并。"); } } } } } }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:網(wǎng)絡(luò)轉(zhuǎn)載