General discussion

Locked

Access Excel 2003 from a C# component

By jarmani ·
I have a customer that wants data from excel printed onto a crystal report. They want the row of data sent the the crystal report at a time. I have created a component that can be called from VBA within excel and sends the data to the report for printing. My problem is sending only one row of data from excel to that component at a time. I was thinking to do so by obtaining the row int (Rows("8:8")) and sending that value to the component, however I do not know how to then select only a specific row of and excel sheet from C#? Can anyone help? Also, is there there a better way? Perhaps sending the row to the .rpt file directly from VBA within excel.
Any thoughts are most appreciated.

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by ahar In reply to Access Excel 2003 from a ...

Im not to familiar with the excel - C# - crystalreport connection, but maybe using a odbc connection to the excelsheet may be tryable.

Collapse -

by amoljpatil In reply to Access Excel 2003 from a ...

- Add the Reference Microsoft Excel 9.0 Object Library into the project.
- Create the object of Excel.Application() class (suppose objExcel is the object of the Excel.Application() class).
- Call to Open a Workbook in Excel:
using ObjExcel.Workbooks.Open() method (pass the parameters)
- Get the colletion of the sheet:
Excel.Sheets objSheets = objWorkbook.Worksheets;
- get the Nth from the collection of worksheets:
Excel.Worksheet objWorksheet = (Excel.Worksheet)sheets.get_Item(N); (where N is 1,2 etc according to the sheet1,sheet2 etc.).
- And read the rows one by one vis for loop.
for (int i = 1; i <= NthROW; i++)
{
Excel.Range range = objWorksheet.get_Range("Col1"+i.ToString(), "Col10" + i.ToString());

string strValue = range.Cells.Value;

}

this will return the value.

In this way you can read the 8 rows:8 Column values.

Cheers,

Amol Patil

Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Forums