Visualizzazione dei risultati da 1 a 4 su 4

Discussione: Creazione Doc

  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2009
    Messaggi
    83

    Creazione Doc

    Ciao,
    ho un nuovo problema,sto tentando di creare un documento word da un template dot
    questo è il mio codice
    codice:
      object oMissing = System.Reflection.Missing.Value;
    
                object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
    
                //Start Word and create a new document.
    
                Word._Application oWord;
    
                Word._Document oDoc;
    
                oWord = new Word.Application();
    
    
                String path = HttpContext.Current.Request.ApplicationPath;
    
                // object oTemplate = "~/Resources/template.dot";
    
                object oTemplate = "C:\\Sviluppo\\BNL\\Patrimonio\\BNLGestionePatrimonio\\BNLGestionePatrimonio\\Resources\\Doc\\templateSIM.dot";
    
                oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing,
    
                ref oMissing, ref oMissing);
    
                String nomeFile = "IT-115-VAC-VerbaleAccettazione";
    
                object oBookMark = "progetto";
    
                // oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = "PRG";
    
                oBookMark = "codice";
    
    
    
                // pathDest = "C:\\inetpub\\wwwroot\\GestSIM\\Documenti\\";
    
                oWord.ActiveDocument.SaveAs("C:\\Sviluppo\\BNL\\Patrimonio\\BNLGestionePatrimonio\\BNLGestionePatrimonio\\" + nomeFile + ".doc", ref oMissing);
    
                oWord.ActiveDocument.Close();
    
                oWord.Quit();
    
    
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);
    
    
                oWord = null;
    e questo è l'errore
    codice:
    Il filtro messaggi ha indicato che l'applicazione è impegnata. (Eccezione da HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER)) 
    Descrizione: Eccezione non gestita durante l'esecuzione della richiesta Web corrente. Per ulteriori informazioni sull'errore e sul suo punto di origine nel codice, vedere la traccia dello stack. 
    
    Dettagli eccezione: System.Runtime.InteropServices.COMException: Il filtro messaggi ha indicato che l'applicazione è impegnata. (Eccezione da HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))
    
    Errore nel codice sorgente: 
    
    
    Riga 50:             // pathDest = "C:\\inetpub\\wwwroot\\GestSIM\\Documenti\\";
    Riga 51: 
    Riga 52:             oWord.ActiveDocument.SaveAs("C:\\Sviluppo\\BNL\\Patrimonio\\BNLGestionePatrimonio\\BNLGestionePatrimonio\\" + nomeFile + ".doc", ref oMissing);
    Riga 53: 
    Riga 54:             oWord.ActiveDocument.Close();
     
    
    File di origine: C:\Sviluppo\BNL\Patrimonio\BNLGestionePatrimonio\BNLGestionePatrimonio\Default.aspx.cs    Riga: 52 
    
    Traccia dello stack: 
    
    
    [COMException (0x8001010a): Il filtro messaggi ha indicato che l'applicazione è impegnata. (Eccezione da HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))]
       Microsoft.Office.Interop.Word._Document.SaveAs(Object& FileName, Object& FileFormat, Object& LockComments, Object& Password, Object& AddToRecentFiles, Object& WritePassword, Object& ReadOnlyRecommended, Object& EmbedTrueTypeFonts, Object& SaveNativePictureFormat, Object& SaveFormsData, Object& SaveAsAOCELetter, Object& Encoding, Object& InsertLineBreaks, Object& AllowSubstitutions, Object& LineEnding, Object& AddBiDiMarks) +0
       BNLGestionePatrimonio._Default.Page_Load(Object sender, EventArgs e) in C:\Sviluppo\BNL\Patrimonio\BNLGestionePatrimonio\BNLGestionePatrimonio\Default.aspx.cs:52
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
       System.Web.UI.Control.LoadRecursive() +71
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3048
    Potete aiutarmi
    Grazie!!!!!!!!!!

  2. #2
    ciao, come abbiamo detto oramai tante volte in questo forum, ripeto che è vivamente sconsigliato utilizzare le librerie Interop da applicazione asp.net:
    http://forum.html.it/forum/showthrea...9#post13353589

    ti consiglio magari di utilizzare OpenXML

    ciao

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2009
    Messaggi
    83
    si ho capito pero io uso le interop perche ho bisogno di prendere un file .dot come template (perchè dentro il file ho dei segnalibri che dopo vado a modificare con dei dati) e invece con le librerie suggerite da te non ci riesco se hai un esempio del genere te ne sarei grato......
    Comunque volevo scusarmi se sto rompendo con questo argomento ma è veramente importante ....Ogni soluzione è accetata

    Ancora grazie

  4. #4
    Utente di HTML.it
    Registrato dal
    Oct 2009
    Messaggi
    83
    Ciao a tutti sono riuscito ad creare questo doc e ad uplodarlo in remeto .
    Ho dovuto cambiare le librerie che usavo come voi mi avete suggerito ...
    Qua sotto metto il codice

    Grazie di tutto!!!!!!!!!!
    codice:
      string templateDoc = string.Format("{0}{1}", "C:\\Doc\\", "temp.dotx");
                string filename = string.Format("{0}{1}.docx", "C:\\Doc\\", 123);
                // Copy a new file name from template file
                File.Copy(templateDoc, filename, true);
                // Open the new Package
                Package pkg = Package.Open(filename, FileMode.Open, FileAccess.ReadWrite);
                // Specify the URI of the part to be read
                Uri uri = new Uri("/word/document.xml", UriKind.Relative);
                PackagePart part = pkg.GetPart(uri);
                XmlDocument xmlMainXMLDoc = new XmlDocument();
                xmlMainXMLDoc.Load(part.GetStream(FileMode.Open, FileAccess.Read));
               
                
                xmlMainXMLDoc.InnerXml = ReplacePlaceHoldersInTemplate(xmlMainXMLDoc.InnerXml);
               
                // Open the stream to write document
                StreamWriter partWrt = new StreamWriter(part.GetStream(FileMode.Open, FileAccess.Write));
                //doc.Save(partWrt);
                xmlMainXMLDoc.Save(partWrt);
                partWrt.Flush();
                partWrt.Close();
                pkg.Close();
                File.Copy("C:\\Doc\\123.docx", "C:\\Doc\\Copy.docx");
    
    
                WebResponse response = null;
    
                WebRequest request = WebRequest.Create(new Uri(new Uri("http://iweb/dirit/Processi Progetti e Applicazioni/Patrimoni/PAT023-Incassi e Pagamenti/Sigle Servizio/TW - Tesoreria Enti/SIM/SIM.doc"), "SIMUFFICIALE.doc"));
                // System.Web.HttpContext.Current.User
                WindowsPrincipal p = Thread.CurrentPrincipal as WindowsPrincipal;
                String utenza = Environment.UserName;
    
                request.Credentials = new System.Net.NetworkCredential("EXTCORD", "BNL72011", "ITA");
    
                request.Method = "PUT";
                // Allocate a 1 KB buffer to transfer the file contents.
                // You can adjust the buffer size as needed, depending on
                // the number and size of files being uploaded.
                byte[] buffer = new byte[1024];
                // Write the contents of the local file to the
                // request stream.
                using (Stream stream = request.GetRequestStream())
                using (FileStream fsWorkbook = File.Open("C:\\Doc\\Copy.doc",
    
                FileMode.Open, FileAccess.Read))
                {
                    int i = fsWorkbook.Read(buffer, 0, buffer.Length);
                    while (i > 0){
                        stream.Write(buffer, 0, i);
                        i = fsWorkbook.Read(buffer, 0, buffer.Length);
                    }
                    stream.Close();
                }
                try {
                // Make the PUT request.
                    response = request.GetResponse();
                //}
                catch (Exception ex)
                {
    
                };
    
     
    
    
    
    
    
            }
    
    
    
            private string ReplacePlaceHoldersInTemplate(string templateBody)
            {
                //templateBody = templateBody.Replace("#IdIncident#",);
                
    
                const string docXml = "<w:tbl><w:tr><w:tc><w:p><w:r><w:t>1</w:t></w:r></w:p></w:tc></w:tr></w:tbl>";
                //templateBody = templateBody.Replace("#requisiti#", docXml);
                //String stable = "<TABLE><ROW><CELL ><para>Apple</para></CELL>";
                //stable = stable + "<CELL><para>Orange</para></CELL></ROW>";
                //stable = stable + "<ROW><CELL><para>Watermelon</para></CELL>";
                //stable = stable +
                 
                ////templateBody = templateBody.Replace("#modifiche#", stable);
                //String stable = "<TABLE><TR><TD>Apple</TD>";
                //stable = stable + "<TD>Orange</TD></TR></TABLE>";
                templateBody = templateBody.Replace("#IdIncident#", docXml);
                return templateBody;
            }

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.