cancel
Showing results for 
Search instead for 
Did you mean: 

How to open a excel document using BSP

Former Member
0 Kudos

Hi All,

We have a Macro. I am opening a excel window with the data from a BSP. The macro should be automatically applied to Excel. I am writing JavaScript in a BSP and please find the code below. It opens data in a Excel window but the macro is not getting applied automatically. Any Suggestions?

function export_to_excel()

{

//cadrDetails = document.getElementById("cadrDetails");

var oExcel = new ActiveXObject("Excel.Application");

oBook = oExcel.Workbooks.Add("C:/\Program Files/\Microsoft Office/\Templates/\DPS_CAD.xlt");

//oSheet = oBook.Worksheets(1);

oSheet = oExcel.Workbooks(1).Sheets(1);

oSheet = oExcel.Workbooks(1).Sheets("Sheet1");

var rowSpanCells = new Array(cadrDetails.rows.length+1);

// Create table with actual rows and columns.

// HTML hides those rows/cols impacted by row/colspan

for (var y=0;y<cadrDetails.rows.length1;y+) {

rowSpanCells[y] = new Array(cadrDetails.rows(0).cells.length + 1);

}

excelRow = 1;

excelCol = 1;

for (var y=0;y<cadrDetails.rows.length;y+,excelRow+)

{

excelCol = 1;

for (var x=0;x<cadrDetails.rows(y).cells.length;x++)

{

setExcelText(oSheet, rowSpanCells, cadrDetails.rows(y).cells(x));

}

}

oSheet.Columns.AutoFit;

oSheet.Activate;

oExcel.Visible = true;

//oExcel.UserControl = true;

}

Thanks,

Naga

Accepted Solutions (1)

Accepted Solutions (1)

raja_thangamani
Active Contributor
0 Kudos

Look at the below excel, it has macro, like sum. It will help you..

<%@page language="abap"%>
<html>
  <head>
  </head>
  <body>

    <object id="msx" style="width:100%;height:300px;margin-top:50px"
            classid="clsid:0002E510-0000-0000-C000-000000000046">
      <param name="DisplayTitleBar" value="false"/>
            <param name="HTMLData"  value=""/>
    </object>

    <script type="text/javascript">
      layout_sheet = document.all("msx");


      layout_sheet.Cells(1,5) = 'Test mit einzelner Zelle';
      msx.range('F1').value = 'F1';

      range  = layout_sheet.Range(layout_sheet.Cells(1,1),layout_sheet.Cells(1,4));
      record = "Jahr;Januar;Februar;März";
      range.ParseText(record, ';');

      range  = layout_sheet.Range(layout_sheet.Cells(2,1),layout_sheet.Cells(2,4));
      range.value = [ 2006, '15', '17', '19' ];

      msx.range('a3:d3').value = [ 2007, 33, 15, 13 ];


      msx.range('a4:d4').value = [ 'Summen', '=SUM(B2:B3)', '=SUM(C2:C3)', '=SUM(D2:D3)' ];

      msx.range('b2').NumberFormat = '####.00';
      msx.range('b2').Interior.Color = 'red';

      msx.range('c1:d1').Font.Name = 'Courier';
      msx.range('c1:d1').Font.Color = 'blue';
      msx.range('c1:d1').Font.Size = 12;
      msx.range('c1:d1').Font.Bold = 1;
      layout_sheet.Cells.AutoFitColumns();
    </script>
  </body>
</html>

*Reward each useful answer

Raja T

Former Member
0 Kudos

Hi Raja,

Thanks for your quick reply. I have a macro which is coded using VB is stored @ "C:/\Program Files/\Microsoft Office/\Templates/\DPS_CAD.xlt". I have to enable this macro automatically when i open excel using BSP. I think that i need to change the JavaScript so that it will take the macro file automatically and apply it.

Thanks,

Naga

raja_thangamani
Active Contributor
0 Kudos

I got it.

But i dont think so at runtime, this will identify your C: Drive to open the VB macro.

<i>*Reward each useful answer</i>

Raja T

Answers (1)

Answers (1)

jaideeps
Advisor
Advisor
0 Kudos

hi,

chk this blog..

/people/thomas.jung3/blog/2005/02/23/bsp-and-microsoft-excel--learning-to-live-together-part-2

thanks

jaideep

*reward points if useful..

Former Member
0 Kudos

Hi All,

I found the solution. Added the line below at the end of the function "export_to_excel' in BSP Application.

oExcel.Run ("Macro1");

Where "Macro1" is the VBA procedure in the template ( .XLT file ).

Thanks,

Naga Bokkisam