RSS registrovat login
Navigace: předchozí stranaúvodní strana
knihovna pro práci s XLS v C#

tuto knihovnu mi poslal Blackshark, měla by pracova s XLS soubory.

using
System;
using
System.Collections;
using
System.Windows.Forms;
using
System.Data;
using
Excel;
using
System.Reflection;
namespace
xml03 {
public
class
C_ExcelInterface {
private
Excel.Application xApp;
private
Excel.Workbook xBook;
private
Excel.Worksheet xSheet;
private
Excel.Range xRange;
private
ArrayList SheetsName;
private
int
SheetsCount;
private
bool
Opened;
//-------------------------------------------------------------
private
bool
CheckBorder(
int
max) {
if
(max >= SheetsCount && max <
0
)
return
false
;
else
return
true
; }
//-------------------------------------------------------------
public
C_ExcelInterface() { xApp =
null
; xBook =
null
; xSheet =
null
; xRange =
null
; SheetsName =
new
ArrayList(); SheetsCount =
0
; Opened =
false
; }
//-------------------------------------------------------------
public
void
Done() {
if
(xApp !=
null
) xApp.Quit(); GC.Collect(); }
//-------------------------------------------------------------
public
void
OpenFile(
string
FileName) { xApp =
new
Excel.Application();
//xApp.Visible = true;
xBook = xApp.Workbooks.Open(FileName,
false
,
true
, Missing.Value,Missing.Value , Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); SheetsCount = xBook.Worksheets.Count;
for
(
int
a=
1
; a<=SheetsCount; ++a) { xSheet = (Excel.Worksheet) xBook.Worksheets[a]; SheetsName.Add(xSheet.Name); }; Opened =
true
; }
//-------------------------------------------------------------
public
int
GetCountRow(
string
sheetName)
// VRACI POCET RADEK DANEHO LIST
{
if
(Opened) { xSheet = (Excel.Worksheet)xBook.Worksheets[sheetName]; xRange = xSheet.UsedRange;
return
xRange.Rows.Count; }
return
0
; }
//-------------------------------------------------------------
public
int
GetCountColumn(
string
sheetName)
// VRACI POCET SLOUPCU DANEHO LISTU
{
if
(Opened) { xSheet = (Excel.Worksheet)xBook.Worksheets[sheetName]; xRange = xSheet.UsedRange;
return
xRange.Columns.Count; }
return
0
; }
//-------------------------------------------------------------
public
int
GetCountRow(
int
sheetID)
// VRACI POCET RADEK DANEHO LISTU
{
if
(Opened &&
this
.CheckBorder(sheetID) ) { xSheet = (Excel.Worksheet)xBook.Worksheets[sheetID]; xRange = xSheet.UsedRange;
return
xRange.Rows.Count; }
return
0
; }
//-------------------------------------------------------------
public
int
GetCountColumn(
int
sheetID)
// VRACI POCET SLOUPCU DANEHO LISTU
{
if
(Opened &&
this
.CheckBorder(sheetID) ) { xSheet = (Excel.Worksheet)xBook.Worksheets[sheetID]; xRange = xSheet.UsedRange;
return
xRange.Columns.Count; }
return
0
; }
//-------------------------------------------------------------
public
string
[] GetSheetsName()
// VRACI JMENA LISTU V XLS DOKUMENTU
{
if
(Opened) {
string
[] sName =
new
string
[SheetsCount];
for
(
int
a=
0
; a!=SheetsCount; ++a) { sName[a] = SheetsName[a].ToString(); };
return
sName; };
return
null
; }
//-------------------------------------------------------------
public
int
GetSheetCount()
// VRACI POCET LISTU V OTEVRENEM XLS DOKUMENTU
{
return
SheetsCount; }
//-------------------------------------------------------------
public
string
GetCellValue(
string
sheetName,
int
ColumnID,
int
RowID) {
int
cc =
this
.GetCountColumn(sheetName);
int
cr =
this
.GetCountRow(sheetName);
if
(ColumnID >= cc || RowID >= cr )
return
null
; xSheet = (Excel.Worksheet) xBook.Worksheets[sheetName]; xRange = xSheet.UsedRange;
object
[,] xData; xData = (System.Object[,]) xRange.get_Value( Missing.Value );
return
xData[RowID,ColumnID].ToString(); }
//-------------------------------------------------------------
} }

Syntax higlighted by Syntax highlighter, available at www.4ITDevelopers.net and www.JakNaWin.com


Informace ke stavu builder.cz zde


vytvořil Mi.Chal. 16.5. 2006 16:52, naposledy změněnil BlackShark 17.5. 2006 16:24
přečteno: 3202x

Komentáře:
Žádné komentáře dosud nebyly vloženy.

Přidat komentář:
Jméno
E-mail
Web
Titulek
Obsah
thomas sabo rea mbt outlet thomas sabo charms sale louis vuitton taschen kaufen thomas sabo boutique mbt kaufen