AxSpreadsheet Help !!!

D

Daniel Junges

Dear users and developers,

I want to use on my C# application an windows form containing an
AxSpreadsheet to load xls files for
the user to edit it.

I dont found a way to load an xls file into AxSpreadsheet!
can any one help me please?

thanks
Daniel Junges
 
Q

quartz

Daniel,

There may be better methods, but the only way I could get that to work (and
I ONLY work in VBA, not C#) was to retrieve the data into a recordset, then
loop through the recordset and write the data into the ActiveX Spreadsheet
control.

I didn't post any code because I figured VBA won't help you much...

HTH.
 
D

Daniel Junges

Hi, i found a solution to import the data, its not a fine solution but i
dont found a better way to do it. Now i have to pass the formating.
I can't understand wy isn't possible to open a file with AxSpreadsheet :-(

Excel.Application excelApp = new Excel.ApplicationClass();
Excel.Workbook excelWorkbook = null;
string workbookPath = "C:\\Book1.xls";
excelWorkbook = excelApp.Workbooks.Open(workbookPath,
0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
true, false, 0, true);

Excel.Sheets sheets = excelWorkbook.Worksheets;
Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1);

for(int c=1; c<=10; c++){ // From A1 to J10
String CC = "" + (char)(64 + c);
Excel.Range range = worksheet.get_Range(CC + "1", CC + "10" );
System.Array myvalues = (System.Array)range.Cells.Value;
for (int i = 1; i <= myvalues.Length; i++) {
if (myvalues.GetValue(i, 1) == null)
axSpreadsheet1.ActiveSheet.Cells[i, c] = "";
else{
String val = (string)myvalues.GetValue(i, 1).ToString();
axSpreadsheet1.ActiveSheet.Cells[i, c] = val;
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top