none
ASP, IIS 6.0, Javascript and Microsoft Word 2013 RRS feed

  • Question

  • Hello everyone,<o:p></o:p>

    hope someone has some nice idea to help us today!<o:p></o:p>

    We are running an asp based application on a windows server with IIS 6.0,  (ODBC = dBASE, xls, mdb). our application first collect data from database tables, it open an .doc file (objword.Documents.Open and var objword = new ActiveXobject ("word.application") and populate data in the document called tax.doc or tax.docx (Rows and Cells).<o:p></o:p>

    We use Javascript code to accomplish that. It works fine with the MS Word version 2010 but not in Word 2013.<u1:p></u1:p><o:p></o:p>

    strange enough, that the Word 2013 open out tax.doc or tax.docx template well, but without any data been populate in the Rows, Cells as it does in Word 2010.<u1:p></u1:p><o:p></o:p>

    my question:<o:p></o:p>

    Anyone, any idea why? And what is not included or has been removed/turned off  in Word 2013?<o:p></o:p>

     

    <u1:p>thank you in adv.</u1:p><o:p></o:p>

    Fraidon

    Tuesday, January 31, 2017 3:24 PM

All replies

  • Hello Fraidon,

    > We are running an asp based application on a windows server with IIS 6.0

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.

    As a workaround you may consider using third-party components designed for the server-side execution. Also you may consider using Open XML SDK for processing open XML documents only. See Welcome to the Open XML SDK 2.5 for Office for more information.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    • Proposed as answer by Eugene Astafiev Thursday, February 2, 2017 11:09 AM
    Tuesday, January 31, 2017 8:21 PM
  • Hi FraidonNaistani,

    I agree with the suggestion given by Eugene  Astafiev.

    if you are using Office interop then in some conditions and situations it will not work properly on server side.

    so in that case you can try to use open XML.

    but you had mentioned that you are using JavaScript to populate the data in word file.

    if so, then please try to post your code.

    we will try to test it on our side and if possible we will try to solve the problem.

    without code we can't suggest anything as we don't know what is your code and how it works.

    so if it possible for you then post a demo code that can reproduce the issue on our side.

    if you are not able to post then you can try to use Open XML.

    if you are getting error then please post the error with its description. it will help us to understand the issue.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 1, 2017 1:22 AM
    Moderator
  • Hello Eugene,<o:p></o:p>

    thank you for the workaround.<o:p></o:p>


     


     
    Thursday, February 2, 2017 11:06 AM
  • Hi Deepak,<o:p></o:p>

    thank you. here some code that we use it. Fortunately has NO issue with Word 2010.

    -------------------------------------------------------------------------------------------------------

    <SCRIPT LANGUAGE="JavaScript">
      <% templatename = Applicationservername & "/templates/factuur_docx.docx" %>
     
     var objWord = new ActiveXObject("Word.application");
     objWord.visible = true;
     objWord.Documents.Open("<%= templatename %>"); 
    </SCRIPT>  
    <%
    Session.LCID = 1043
    %>
    <!--<table width=480 cellpadding=0 cellspacing=0>-->
    <tr><td align=left width=90><br></td></tr>
    <tr><td align=left><font face="Arial" size="2"><b>Proj Nr.</b>&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><b><%= rs("projNo")%> </b></font></td></tr>

    <tr><td align=left><font face="Arial" size="2">Omschrijving:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= RS("projDesc") %></font></td></tr>

    <tr><td align=left><font face="Arial" size="2">Bedrijf:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= RS("projBedrijf") %></font></td></tr>

    <tr><td align=left><font face="Arial" size="2">Afdeling:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= BillAfdeling %></font></td></tr>

    <tr><td align=left><font face="Arial" size="2">Straat:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= BillAdres %></font></td></tr>

    <tr><td align=left><font face="Arial" size="2">Plaats:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= postcodeplaats %></font></td></tr>

    <tr><td align=left><font face="Arial" size="2">Debit Nr.:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= RS("projDebitNo") %></font></td></tr>

    <tr><td align=left><font face="Arial" size="2">PO nr.:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= RS("projPO") %></font></td></tr>

    <tr><td align=left><font face="Arial" size="2">Type:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= RS("projType") %></font></td></tr>

    <tr><td align=left><font face="Arial" size="2">Registered Medewerker:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= regEmp %></font></td></tr>

    <tr><td align=left><font face="Arial" size="2">Acc. Man.:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= accMan %></font></td></tr>

    <tr><td align=left><font face="Arial" size="2">Prep. Dagen:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= RS("projCoursePrepDays") %> ( &aacute; € <%= FormatNumber(RS("projCoursePrep")) %> per dag - <%= RS("projCoursePrepBillable") %>% billable)</font></td></tr>

    <tr><td align=left><font face="Arial" size="2">Course Dagen:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= RS("projCourseTariefDays") %> ( &aacute; € <%= FormatNumber(RS("projCourseTarief")) %> per dag - <%= RS("projCourseBillable") %>% billable)</font></td></tr>

    <%
     if RS("projCourseLicense") = 1 then
    %>
    <tr><td align=left><font face="Arial" size="2">Licentie:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= RS("projCourseLicenseFee")%> </font></td></tr>
    <%
     end if
      if RS("projCourseMiscInclude") > 0 then 
    %>
    <tr><td align=left><font face="Arial" size="2">Gemengd:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= RS("projCourseMisc") %> </font></td></tr>
    <% 
     end if

     if kmscontrol = 1 then
    %>
    <tr><td align=left><font face="Arial" size="2">Kms:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= kms(0) %> ( &aacute; € <%= RS("projCourseKmsTarief") %> per KM )</font></td></tr>
    <%
    textKms = "Reiskosten, "& RSk("Expr1000")&" km á € "& RS("projCourseKmsTarief") 
    else
    textKms = ""
    end if

    row = 16
    Session.LCID = 1043
    %>

    <tr><td align=left><font face="Arial" size="2">SubTotaal:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= SubTotaal(0) %></font></td></tr>

    <tr><td align=left nowrap><font face="Arial" size="2">BTW (<%= percent(0) * 100 %>%):&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= tax %></font></td></tr>

    <tr><td align=left><font face="Arial" size="2">Totaal:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= TotaalF(0) %></font></td></tr>
    <!--</table>-->


    <SCRIPT LANGUAGE="JavaScript">

    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(1).Cells.Item(1).Range="<%= rs("projBedrijf") %>";
    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(2).Cells.Item(1).Range="<%= BillAfdeling %>";
    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(3).Cells.Item(1).Range="<%= BillAdres %>";
    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(4).Cells.Item(1).Range="<%= postcodeplaats %>";

    //objWord.Documents.Item(1).Tables.Item(1).Rows.Item(11).Cells.Item(3).Range="<%= rs("projNo") %>";
    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(12).Cells.Item(3).Range="<%= rs("projDebitNo") %>";
    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(13).Cells.Item(3).Range="<%= rs("projPO") %>";


    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(15).Cells.Item(3).Range="<%= btwnummer %>";




    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(16).Cells.Item(3).Range="<%= projBij %>";

    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(18).Cells.Item(1).Range="<%= textintro %>";
    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(19).Cells.Item(1).Range="<%= textKms %>";
    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(20).Cells.Item(1).Range="<%= textLicense %>";
    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(21).Cells.Item(1).Range="<%= textMisc %>";


    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(18).Cells.Item(2).Range="€";
    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(19).Cells.Item(2).Range="<%= SubTotaalKmsE %>";
    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(20).Cells.Item(2).Range="<%= SubTotaalLisE %>";
    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(21).Cells.Item(2).Range="<%= SubTotaalMiscE%>";

    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(18).Cells.Item(3).Range="<%= SubTotaalHrs %>";
    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(19).Cells.Item(3).Range="<%= kmsstring %>";
    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(20).Cells.Item(3).Range="<%= SubTotaalLis %>";
    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(21).Cells.Item(3).Range="<%= SubTotaalMisc%>";

    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(23).Cells.Item(4).Range="<%= SubTotaal(0) %>";
    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(25).Cells.Item(2).Range="B.T.W.(<%= percent(0) * 100 %>%)";
    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(25).Cells.Item(4).Range="<%= tax %>";
    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(26).Cells.Item(4).Range="<%= TotaalF(0) %>";


    objWord.Documents.Item(1).Tables.Item(1).Rows.Item(27).Cells.Item(4).Range="Wij verzoeken u vriendelijk om betaling van deze factuur binnen <%= projTerm %> dagen na dagtekening."
    //objWord.Documents.close;

    </script>

    <%
    else
    %>
    <table width=480 cellpadding=0 cellspacing=0>
    <tr><td align=left><font face="Arial" size="2"><b>Proj Nr.</b>&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><b><%= rs("projNo")%></b></font></td></tr>

    <tr><td align=left><font face="Arial" size="2">Omschrijving:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= RS("projDesc") %></font></td></tr>

    <tr><td align=left><font face="Arial" size="2">Bedrijf:&nbsp;</font></td>
    <td align=left><font face="Arial" size="2"><%= RS("projBedrijf") %></font></td></tr>

    <tr><td align=left width=90><br></td></tr>
    <tr><td align=left><font face="Arial" size="2"><b>No hours recorded</b></font></td>
    </tr></table>

    <%

    end if




    end if
    end if



    RSmedewerker.close
    next 'RSmedewerkerloop - loop through proj medewerkers
    end if
    RS.movenext 
    wend 'loop through proj to get selected ones!!

    %>
    </table>

    <tr><td colspan=4><br /></td></tr>

    <tr><td colspan="4">
    <input type="button" value="Sluit Window" onClick="winclose();">
    <!--//<input type="submit" name="B1" value="Print" onclick="window.print()">-->

    </td></tr>
    </table>
    </form>
    </body>
    </html>

    <o:p></o:p>

    Thursday, February 2, 2017 11:08 AM
  • Hi FraidonNaistani,

    I can see that nothing wrong with the code.

    so I think issue occurs because you run on server side.

    so as per other community member already suggested you can try to use Open Xml to perform this task.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, February 3, 2017 8:35 AM
    Moderator
  • Hi Deepak,

    Thank you for the advice. as I mentioned before we have No issue/problem when we open this application with Microsoft Word 2010. My prediction is,  that some elements are changed in the Microsoft Word 2013.  

    Best regards,

    Fraidon Naistani

     


    Fraidon Naistani

    Thursday, February 9, 2017 9:18 AM
  • Hi FraidonNaistani,

    elements remain the same , the issue is occur because some of the feature , functionality has been change with the new MS Office Version that run in background and interact with server.

    and Office interop does not provide anything to check , handle or to correct it.

    so we don't have any control on that, programmatically we can't do anything as already mentioned in the documentation.

    you predict that it's because changes of elements in document but you can test the same document with different version of MS Office and it will give you different results.

    so the document remain same then also you get different results , so its an issue with Office Version not with document.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, February 10, 2017 12:41 AM
    Moderator