Skip to main content

Im having a problem with one line below, can anyone advise ????

the problem line is 

set worksheet = workbook::ActiveSheet

from the c#

workbook.ActiveSheet

 

 

* // Creating a Excel object.
* Microsoft.Office.Interop.Excel._Application excel = new Microsoft.Office.Interop.Excel.Application();
* Microsoft.Office.Interop.Excel._Workbook workbook = excel.Workbooks.Add(Type.Missing);
* Microsoft.Office.Interop.Excel._Worksheet worksheet = null;

declare excel as type Microsoft.Office.Interop.Excel._Application = new type Microsoft.Office.Interop.Excel.Application
declare workbook as type Microsoft.Office.Interop.Excel._Workbook = excel::Workbooks::Add(type System.Type::Missing)
declare worksheet as type Microsoft.Office.Interop.Excel._Worksheet = null

try
* worksheet = workbook.ActiveSheet
set worksheet = workbook::ActiveSheet

* worksheet.Name = "ExportedFromDatGrid"
set worksheet::Name = "ExportedFromDataGrid"

* int cellRowIndex = 1;
declare cellRowIndex as binary-short = 1

* int cellColumnIndex = 1;
declare cellColumnIndex as binary-short = 1

declare i as binary-short = 0
declare j as binary-short = 0

* //Loop through each row and read value from each column.
* for (int i = 0; i < dgvCityDetails.Rows.Count - 1; i )
perform varying i from 0 by 1 until i < dgvMain::Rows::Count - 1
* {
* for (int j = 0; j < dgvCityDetails.Columns.Count; j )
perform varying j from 0 by 1 until j < dgvMain::Columns::Count
* {
* // Excel index starts from 1,1. As first Row would have the Column headers, adding a condition check.
* if (cellRowIndex == 1)
if cellRowIndex = 1
* {
* worksheet.Cells[cellRowIndex, cellColumnIndex] = dgvCityDetails.Columns.HeaderText;
set worksheet::Cells[cellRowIndex, cellColumnIndex] = dgvMain::Columns::HeaderText
* }
else
* {
* worksheet.Cells[cellRowIndex, cellColumnIndex] = dgvCityDetails.Rows.Cells.Value.ToString();
set worksheet::Cells[cellRowIndex, cellColumnIndex] = dgvMain::Rows::Cells::Value::ToString()
* }
end-if
* cellColumnIndex ;
set cellColumnIndex = cellColumnIndex 1
* }
end-perform
* cellColumnIndex = 1;
set cellColumnIndex = 1
* cellRowIndex ;
set cellRowIndex = cellRowIndex 1
* }
end-perform


catch
continue
end-try

Im having a problem with one line below, can anyone advise ????

the problem line is 

set worksheet = workbook::ActiveSheet

from the c#

workbook.ActiveSheet

 

 

* // Creating a Excel object.
* Microsoft.Office.Interop.Excel._Application excel = new Microsoft.Office.Interop.Excel.Application();
* Microsoft.Office.Interop.Excel._Workbook workbook = excel.Workbooks.Add(Type.Missing);
* Microsoft.Office.Interop.Excel._Worksheet worksheet = null;

declare excel as type Microsoft.Office.Interop.Excel._Application = new type Microsoft.Office.Interop.Excel.Application
declare workbook as type Microsoft.Office.Interop.Excel._Workbook = excel::Workbooks::Add(type System.Type::Missing)
declare worksheet as type Microsoft.Office.Interop.Excel._Worksheet = null

try
* worksheet = workbook.ActiveSheet
set worksheet = workbook::ActiveSheet

* worksheet.Name = "ExportedFromDatGrid"
set worksheet::Name = "ExportedFromDataGrid"

* int cellRowIndex = 1;
declare cellRowIndex as binary-short = 1

* int cellColumnIndex = 1;
declare cellColumnIndex as binary-short = 1

declare i as binary-short = 0
declare j as binary-short = 0

* //Loop through each row and read value from each column.
* for (int i = 0; i < dgvCityDetails.Rows.Count - 1; i )
perform varying i from 0 by 1 until i < dgvMain::Rows::Count - 1
* {
* for (int j = 0; j < dgvCityDetails.Columns.Count; j )
perform varying j from 0 by 1 until j < dgvMain::Columns::Count
* {
* // Excel index starts from 1,1. As first Row would have the Column headers, adding a condition check.
* if (cellRowIndex == 1)
if cellRowIndex = 1
* {
* worksheet.Cells[cellRowIndex, cellColumnIndex] = dgvCityDetails.Columns.HeaderText;
set worksheet::Cells[cellRowIndex, cellColumnIndex] = dgvMain::Columns::HeaderText
* }
else
* {
* worksheet.Cells[cellRowIndex, cellColumnIndex] = dgvCityDetails.Rows.Cells.Value.ToString();
set worksheet::Cells[cellRowIndex, cellColumnIndex] = dgvMain::Rows::Cells::Value::ToString()
* }
end-if
* cellColumnIndex ;
set cellColumnIndex = cellColumnIndex 1
* }
end-perform
* cellColumnIndex = 1;
set cellColumnIndex = 1
* cellRowIndex ;
set cellRowIndex = cellRowIndex 1
* }
end-perform


catch
continue
end-try

nope thats not it you can substitute 'to' with '=' in .NET Cobol

Im having a problem with one line below, can anyone advise ????

the problem line is 

set worksheet = workbook::ActiveSheet

from the c#

workbook.ActiveSheet

 

 

* // Creating a Excel object.
* Microsoft.Office.Interop.Excel._Application excel = new Microsoft.Office.Interop.Excel.Application();
* Microsoft.Office.Interop.Excel._Workbook workbook = excel.Workbooks.Add(Type.Missing);
* Microsoft.Office.Interop.Excel._Worksheet worksheet = null;

declare excel as type Microsoft.Office.Interop.Excel._Application = new type Microsoft.Office.Interop.Excel.Application
declare workbook as type Microsoft.Office.Interop.Excel._Workbook = excel::Workbooks::Add(type System.Type::Missing)
declare worksheet as type Microsoft.Office.Interop.Excel._Worksheet = null

try
* worksheet = workbook.ActiveSheet
set worksheet = workbook::ActiveSheet

* worksheet.Name = "ExportedFromDatGrid"
set worksheet::Name = "ExportedFromDataGrid"

* int cellRowIndex = 1;
declare cellRowIndex as binary-short = 1

* int cellColumnIndex = 1;
declare cellColumnIndex as binary-short = 1

declare i as binary-short = 0
declare j as binary-short = 0

* //Loop through each row and read value from each column.
* for (int i = 0; i < dgvCityDetails.Rows.Count - 1; i )
perform varying i from 0 by 1 until i < dgvMain::Rows::Count - 1
* {
* for (int j = 0; j < dgvCityDetails.Columns.Count; j )
perform varying j from 0 by 1 until j < dgvMain::Columns::Count
* {
* // Excel index starts from 1,1. As first Row would have the Column headers, adding a condition check.
* if (cellRowIndex == 1)
if cellRowIndex = 1
* {
* worksheet.Cells[cellRowIndex, cellColumnIndex] = dgvCityDetails.Columns.HeaderText;
set worksheet::Cells[cellRowIndex, cellColumnIndex] = dgvMain::Columns::HeaderText
* }
else
* {
* worksheet.Cells[cellRowIndex, cellColumnIndex] = dgvCityDetails.Rows.Cells.Value.ToString();
set worksheet::Cells[cellRowIndex, cellColumnIndex] = dgvMain::Rows::Cells::Value::ToString()
* }
end-if
* cellColumnIndex ;
set cellColumnIndex = cellColumnIndex 1
* }
end-perform
* cellColumnIndex = 1;
set cellColumnIndex = 1
* cellRowIndex ;
set cellRowIndex = cellRowIndex 1
* }
end-perform


catch
continue
end-try

If ActiveSheet returns an object, you may need to explicitly cast it.

set worksheet = workbook::ActiveSheet as type Microsoft.Office.Interop.Excel._Worksheet


Im having a problem with one line below, can anyone advise ????

the problem line is 

set worksheet = workbook::ActiveSheet

from the c#

workbook.ActiveSheet

 

 

* // Creating a Excel object.
* Microsoft.Office.Interop.Excel._Application excel = new Microsoft.Office.Interop.Excel.Application();
* Microsoft.Office.Interop.Excel._Workbook workbook = excel.Workbooks.Add(Type.Missing);
* Microsoft.Office.Interop.Excel._Worksheet worksheet = null;

declare excel as type Microsoft.Office.Interop.Excel._Application = new type Microsoft.Office.Interop.Excel.Application
declare workbook as type Microsoft.Office.Interop.Excel._Workbook = excel::Workbooks::Add(type System.Type::Missing)
declare worksheet as type Microsoft.Office.Interop.Excel._Worksheet = null

try
* worksheet = workbook.ActiveSheet
set worksheet = workbook::ActiveSheet

* worksheet.Name = "ExportedFromDatGrid"
set worksheet::Name = "ExportedFromDataGrid"

* int cellRowIndex = 1;
declare cellRowIndex as binary-short = 1

* int cellColumnIndex = 1;
declare cellColumnIndex as binary-short = 1

declare i as binary-short = 0
declare j as binary-short = 0

* //Loop through each row and read value from each column.
* for (int i = 0; i < dgvCityDetails.Rows.Count - 1; i )
perform varying i from 0 by 1 until i < dgvMain::Rows::Count - 1
* {
* for (int j = 0; j < dgvCityDetails.Columns.Count; j )
perform varying j from 0 by 1 until j < dgvMain::Columns::Count
* {
* // Excel index starts from 1,1. As first Row would have the Column headers, adding a condition check.
* if (cellRowIndex == 1)
if cellRowIndex = 1
* {
* worksheet.Cells[cellRowIndex, cellColumnIndex] = dgvCityDetails.Columns.HeaderText;
set worksheet::Cells[cellRowIndex, cellColumnIndex] = dgvMain::Columns::HeaderText
* }
else
* {
* worksheet.Cells[cellRowIndex, cellColumnIndex] = dgvCityDetails.Rows.Cells.Value.ToString();
set worksheet::Cells[cellRowIndex, cellColumnIndex] = dgvMain::Rows::Cells::Value::ToString()
* }
end-if
* cellColumnIndex ;
set cellColumnIndex = cellColumnIndex 1
* }
end-perform
* cellColumnIndex = 1;
set cellColumnIndex = 1
* cellRowIndex ;
set cellRowIndex = cellRowIndex 1
* }
end-perform


catch
continue
end-try

Thanks Ted thats cracked it, but how did you know that ??? is C# different to Visual Cobol on this??

Im having a problem with one line below, can anyone advise ????

the problem line is 

set worksheet = workbook::ActiveSheet

from the c#

workbook.ActiveSheet

 

 

* // Creating a Excel object.
* Microsoft.Office.Interop.Excel._Application excel = new Microsoft.Office.Interop.Excel.Application();
* Microsoft.Office.Interop.Excel._Workbook workbook = excel.Workbooks.Add(Type.Missing);
* Microsoft.Office.Interop.Excel._Worksheet worksheet = null;

declare excel as type Microsoft.Office.Interop.Excel._Application = new type Microsoft.Office.Interop.Excel.Application
declare workbook as type Microsoft.Office.Interop.Excel._Workbook = excel::Workbooks::Add(type System.Type::Missing)
declare worksheet as type Microsoft.Office.Interop.Excel._Worksheet = null

try
* worksheet = workbook.ActiveSheet
set worksheet = workbook::ActiveSheet

* worksheet.Name = "ExportedFromDatGrid"
set worksheet::Name = "ExportedFromDataGrid"

* int cellRowIndex = 1;
declare cellRowIndex as binary-short = 1

* int cellColumnIndex = 1;
declare cellColumnIndex as binary-short = 1

declare i as binary-short = 0
declare j as binary-short = 0

* //Loop through each row and read value from each column.
* for (int i = 0; i < dgvCityDetails.Rows.Count - 1; i )
perform varying i from 0 by 1 until i < dgvMain::Rows::Count - 1
* {
* for (int j = 0; j < dgvCityDetails.Columns.Count; j )
perform varying j from 0 by 1 until j < dgvMain::Columns::Count
* {
* // Excel index starts from 1,1. As first Row would have the Column headers, adding a condition check.
* if (cellRowIndex == 1)
if cellRowIndex = 1
* {
* worksheet.Cells[cellRowIndex, cellColumnIndex] = dgvCityDetails.Columns.HeaderText;
set worksheet::Cells[cellRowIndex, cellColumnIndex] = dgvMain::Columns::HeaderText
* }
else
* {
* worksheet.Cells[cellRowIndex, cellColumnIndex] = dgvCityDetails.Rows.Cells.Value.ToString();
set worksheet::Cells[cellRowIndex, cellColumnIndex] = dgvMain::Rows::Cells::Value::ToString()
* }
end-if
* cellColumnIndex ;
set cellColumnIndex = cellColumnIndex 1
* }
end-perform
* cellColumnIndex = 1;
set cellColumnIndex = 1
* cellRowIndex ;
set cellRowIndex = cellRowIndex 1
* }
end-perform


catch
continue
end-try

The error was that it could not implicitly convert object to _Worksheet, you therefore must do it explicitly using the `AS` or `AS IF` operator.

I think the reason this works in C# is that it automatically uses duck typing for COM objects. So it is effectively doing the following statement.

dynamic worksheet = workbook.ActiveSheet;

There is no support for duck typing in Visual COBOL though, so the casting is still necessary. More information can be found here:

jinishbhardwaj.wordpress.com/.../