嗨... 我的任务是生成Word文档.通过选择适当的选项,我们可以生成一个文档.我的服务器中有基本文档,如果单击生成",则将生成该文档,我们可以将其保存在本地驱动器中. 如果我现在正在使用门户,并且同时有人在他们的计算机中使用门户,则不会生成文档.它会自动发回. 我想显示一个进度条或类似的东西,以便该人员可以等到文档完全生成后. 使用线程是否可能? 请提供代码帮助, 预先感谢, Anusha
解决方案如果文件正在被其他进程使用,则需要在使用该文件之前先终止该进程.您需要查看如何终止进程 [ ^ ]. 对于某些过程,您将需要管理员权限才能杀死它.您还必须注意这一点. --Amit
嗨Anusha, 除非打开文件的其他实体允许共享读取,否则您将无法执行此操作. 有关更多参考: stackoverflow/Questions/897796/how-do-i-open-an-already-opened-file-with-a-net-streamreader [ ^ ] 问候 sarva
public void UpdateTOC(字符串 file1, string file2) { 使用( var mainDoc = WordprocessingDocument.Open(file1, false )) 使用( var resultDoc = WordprocessingDocument.Create(file2,WordprocessingDocumentType.Document)) { // 将零件从源文档复制到新文档 foreach ( var 零件 in 中的零件)resultDoc.AddPart(part.OpenXmlPart,part.RelationshipId); // 在resultDoc.MainDocumentPart中执行替换////} } }
这是我正在使用的代码.File1是将在服务器中的基础文档,而file2将是将要生成的文档.两个文档都有唯一的名称..
Hi... My task is to generate Word documents. By selecting the appropriate options, we can generate a document. I have the base documents in the server, and if I click generate, then the document will be generated and we can save it on our local drive. If I am using the portal now and, at the same time, if some one is using it in their machine at the same time, then the document is not getting generated. Its automatically getting posted back. I want to show a progress bar or something like that, so that the person waits until the document is completely generated. Is this possible using threads? Please Help with codes, Thanks in advance, Anusha
解决方案 If file is being used by other process then you need to kill the process first before using the file. You need to see How to kill a process[^]. For some process, you''ll require admin privileges to kill it. You''ll have to take care of that also. --Amithi Anusha, You cannot do this unless the other entity which has the file open allows for shared reads. for more ref: stackoverflow/questions/897796/how-do-i-open-an-already-opened-file-with-a-net-streamreader[^] regards sarvapublic void UpdateTOC(string file1, string file2) { using (var mainDoc = WordprocessingDocument.Open(file1, false)) using (var resultDoc = WordprocessingDocument.Create(file2, WordprocessingDocumentType.Document)) { // copy parts from source document to new document foreach (var part in mainDoc.Parts) resultDoc.AddPart(part.OpenXmlPart, part.RelationshipId); // perform replacements in resultDoc.MainDocumentPart // ... } } }This is the code I am using.. File1 is the base document which will be in the server and file2 will be the document that will be generated.. both the documents have unique names..
更多推荐
如何打开其他人在其他计算机上使用的文件
发布评论