|
Hello,
I create 4000 files word like this :
foreach (string s in FUSIONSS_1)
{
String[] tbStr2 = s.Split(new Char[] { ';' });
string nb = tbStr2[0];
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
oWord.Visible = true;
oWord.Visible = false;
Object oTemplatePath = modelee;
oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
bool sympb = false; bool E = false; bool n = false; bool p = false; bool r = false;
foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
{if (range.Text.Trim().Contains("P"))
{ int pos = range.Text.Trim().IndexOf("P");
string str = range.Text.Trim().Replace("P", "O");
range.Text = str;} }
Directory.CreateDirectory((Object)path + "./PUBLI/" + nb);
Object oSaveAsFile = (Object)path + "./PUBLI/" + nb + "/" + nb + ".doc";
oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
oWordDoc.Close(ref oFalse, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
}
unfortunately the process winword.exe don't be kill on the task manager of my server.
How i can close the word file correctly?, thank you verry mutch.
|
|
|
|
|
|
Do you really need to create and dispose of the word application, and the other objects, 4000 times? Don't you think it would be better to do this outside of the loop?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Try changing the first oMissing to false.
abbd wrote: oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
Word may be hanging on a hidden prompt to save changes or suchlike.
|
|
|
|
|
Unfortunately i have the same problem, please help me.
|
|
|
|
|
Well, I used to have a similar problem automating Excel in the same way. Best way to troubleshoot it is to NOT run it invisible for the time being. Then you can see what the problem might be.
|
|
|
|
|
Hello,
How in can run it invisible for the time being? please help me to resolve this great big problem.
|
|
|
|
|
oWord.Visible = true;
oWord.Visible = false;
Take out that second line.
You're running this on a server, right? NOT a good idea according to Microsoft (and my experience).
Also check your DCOM settings to be sure permissions are there for remote running. (I don't remember how to do it...Google will help.)
Actually, the best advice is to find another way to do it. If you can use Word 2007, while not necessarily easier, it's more likely to work beause you don't actually need Word on the server.
(I'll be gone this week, so can't help much. Maybe try Questions & Answers for more.)
|
|
|
|
|
Hello CP, I am back with another question. I am currently displaying data on a form like this:
There is a pie chart that is anchored to the top of the form. Beneath the chart I have a combobox which can alter the chart type. Beneath the chart type selection is the data I have questions about.
For now I am using simple Label controls and I display (each one on a separate label):
Total: 2
Model Model Total Most Common Failure
12345 100 Bad Part #1
54321 15 Bad Part #2
The labels' text is generated simply by retrieving data from the database and appending each model, model total and most common failure to the corresponding label's existing text. This method works.
However, I was approached by my immediate supervisor at work (who is the person I take requests from) about this. He asked if it is possible to make each Model item clickable (hence my link label idea) and display data based on the one specific model. I know I can dynamically generate link labels and set their location accordingly. However, is this an efficient solution or could I go about providing the desired result in another way?
I will continue to Google for possible solutions and if I find a better solution I will post here.
Thanks CP.
|
|
|
|
|
Hi,
I would say LinkLabels work exactly the same as regular Labels; you can add them through Visual Designer, or by executing some code (All Visual Designer ever does is generating such code, typically in a file with a name ending on Designer.cs ).
However, if your data is structured, you should not be using individual labels or linklabels. Consider using a DataGridView instead. It is a more complex control, however it knows about rows and columns (pretty much like a table in a database), you can make it hold any number of rows automatically, have it scroll when its content grows beyond its borders. And you can make it load its data automatically through "data binding".
Some more features that may interest you:
- choose how the data looks in each column, or even in individual cells;
- react to a cell being clicked;
- get the rows sorted based on the column header you click.
Mind you, if you have never used it, it may take some reading up to get acquainted.
I have one example on-line, in my article CP Vanity[^]. It is not the simplest example one could come up with, however it could give you an idea of what is possible.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Thanks, Luc, but I do not think that is the necessary solution. There is not a large amount of data being displayed. The data will almost always fit without the need for scrolling. I simply need a way to have each model clickable and clicking it will display the data in a separate form (I am leaning toward a simple popup-like control). The data that will display is not for permanent viewing, as it is more for quick reference.
I hope I explained the problem more clearly. I find it difficult at times to explain exactly what is going on through simple text. :-P
|
|
|
|
|
Which controls you use is up to you, there is a number of them included in Windows and available as .NET WinForm Controls. You can also build your own, based on UserControl. And there are a large number of commercially available Controls too.
I am very much in favor of ListBox and DataGridView as soon as there is a list of things to be displayed. I would never put 10 or more Controls of the same type on a Form, it becomes hard to program, and performance goes down.
I forgot to mention: you can make a Label react to a click too, there is no need to have a LinkLabel, just look at the Click event.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Yeah, I understand what you're saying. I did get it working with the labels. Thanks much, Luc.
|
|
|
|
|
You're welcome.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
i'm trying to get the unicode value of a character when the character is given , for example, i can get the character using
string s = '\u0061';
so the character is assigned to s , but now i want the vise versa , means i want to get the unicode of the s , the result should be '\u0061'.
any one gat an idea .
thanx in advance.
|
|
|
|
|
Not tested:
string unicode = string.Format("'\\u{0:X4}'", (int)s[0]);
|
|
|
|
|
thanx it works for me thax again.
|
|
|
|
|
He everyone,
within a application i've use a PrintPreviewControl. When calling ProntPage a error-message occour:
<b>Not ImplementedException System.Collections.ListDictionaryInternal</b>
The error comes up in Line:
<b>e.Graphics.DrawImage ( Image, 10,10 );</b>
But only if the program runs within Windows XP (Svp3). Doing under Windows 7 all works well. Ive also tried all versions of .NET Framework (2.0, 3.0, 3.5 4.0) but this does not change anything.
The development is done with VS2010 under Windows 7
Here are the code to test:
<pre>//Form1.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace PrintImageTest
{
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main ()
{
Application.EnableVisualStyles ();
Application.SetCompatibleTextRenderingDefault ( false );
Application.Run ( new Form1 () );
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PrintImageTest
{
public partial class Form1 : Form
{
public Form1 ()
{
InitializeComponent ();
this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler ( printDocument1_PrintPage );
}
void printDocument1_PrintPage ( object sender, System.Drawing.Printing.PrintPageEventArgs e )
{
Bitmap Image = new Bitmap (@"C:\Temp\TestImage.jpg");
e.Graphics.DrawImage ( Image, 10,10 );
}
}
}
<br/>//Forms.Designer.cs
namespace PrintImageTest
{
partial class Form1
{
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
protected override void Dispose ( bool disposing )
{
if ( disposing && ( components != null ) )
{
components.Dispose ();
}
base.Dispose ( disposing );
}
#region Vom Windows Form-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent ()
{
this.printPreviewControl1 = new System.Windows.Forms.PrintPreviewControl ();
this.printDocument1 = new System.Drawing.Printing.PrintDocument ();
this.SuspendLayout ();
//
// printPreviewControl1
//
this.printPreviewControl1.AutoZoom = false;
this.printPreviewControl1.Document = this.printDocument1;
this.printPreviewControl1.Location = new System.Drawing.Point ( 24, 32 );
this.printPreviewControl1.Name = "printPreviewControl1";
this.printPreviewControl1.Size = new System.Drawing.Size ( 401, 432 );
this.printPreviewControl1.TabIndex = 1;
this.printPreviewControl1.Zoom = 0.36783575705731392D;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF ( 6F, 13F );
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size ( 471, 508 );
this.Controls.Add ( this.printPreviewControl1 );
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout ( false );
}
#endregion
private System.Windows.Forms.PrintPreviewControl printPreviewControl1;
private System.Drawing.Printing.PrintDocument printDocument1;
}
}
<br/>
//Programm.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace PrintImageTest
{
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main ()
{
Application.EnableVisualStyles ();
Application.SetCompatibleTextRenderingDefault ( false );
Application.Run ( new Form1 () );
}
}
}
</pre>
I would be very happy if someone could help with this.
Thank you in advance
pfotenh
|
|
|
|
|
Hi,
According to the PrintDocument class documentation, I would rather use
e.PageVisual = Image;
than
e.Graphics.DrawImage ( Image, 10,10 );
in your printDocument1_PrintPage method.
|
|
|
|
|
Hi Phil,
thanks for your answer.
Unfortunately i could not use this implementation (as it only available in .Net-Framework 4.0. I have to use .Net-Framework 3.5. There ist not PageVisual available.
Regards
pfotenh
|
|
|
|
|
Did you try a couple of image files? I suspect your image is broken, or just not supported by GDI+.
PS: please use PRE tags when showing code.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi Lic,
thanks for your help.
Yes, i've tried some images. Also i've worked on two differet machines one with Windows 7 one with windows XP.
The images on Windows 7 always appear correct.
Regards
pfotenh
|
|
|
|
|
JPEG images hold properties, that probably is what .NET is using a collection for, which seems to be failing somehow when your code tries to print them.
My gut feeling still is the problem is not related to printing; so I would suggest you try:
- same images in a WinForms Form+PictureBox;
- other images (from a different source); and maybe a different image type, say PNG or GIF.
I'm puzzled by your XP/7 remark. There could be two causes IMO:
- your XP being 32-bit, and Win7 being 64-bit, thus running completely different GDI+ code;
- your systems having different software revisions, older bugs not having been patched up on XP.
In either case, this is the first such thing I hear in this area.
PS: if you want, you can use the "e-mail" widget below to send me a private e-mail, or just check the "Allow private email" checkbox under the edit box; I would then provide you with my address so you could send me an actual JPEG that causes the problems, for me to look in to.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Problem with Process.Start("WINWORD.EXE", selectedFile);
I even put the entire path there: //string MSWordPath = @"c:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE";
Still same result:
the path and file name is:
c:\Users\xxx\Documents\Visual Studio 2010\Projects\zMAP\bridgeWord-Html\bridgeWord-Html\bin\Debug\01 SettingsForVSC#.docx
The MSWord is lunched but these errors are thrown:
Microsoft Word
This file could not be found!
(c:\Users\xxx\Documents\Visual.doc)
(c:\Users\xxx\Documents\...\Studio.doc)
(c:\Users\xxx\Documents\...\01.doc)
(c:\Users\xxx\Documents\...\Studio.doc)
(c:\Users\xxx\Documents\...\SettingsForVSC#.doc)
And then an empty msword page is open.
[I see it breaks at the spaces in between names] ---How to fix this problem?
I wish to open not only a docx file, but a html file also,or a txt file.
thank you.
string path = Application.StartupPath;
private void button3_Click(object sender, EventArgs e)
{
string MSWordPath = "\"c:\\Program Files (x86)\\Microsoft Office\\Office14\\WINWORD.EXE\"";
selectedFile = path + "\\" + listBox1.SelectedItem as string;
Process.Start(MSWordPath, selectedFile);
}
modified on Friday, May 20, 2011 1:13 PM
|
|
|
|
|
Enclose the entire path to all filepaths, even your winword.exe, in double quotes. Your command line would end up looking like this:
"C:\Program Files (x86)\Microsoft Office\Office14\WinWord.exe" "C:\Users\xxxx\Documents\Visual Studio 2010\...\01SettingsForVSC#.doc"
The quotes MUST be part of the string, otherwise any spaces in the path will deliniate a parameter for the command line.
|
|
|
|
|