Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6f0daea

Browse files
migrated to .net 8
1 parent b426465 commit 6f0daea

21 files changed

+166
-351
lines changed
File renamed without changes.
File renamed without changes.
Lines changed: 94 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,94 @@
1-
using DevExpress.XtraRichEdit;
2-
using DevExpress.XtraRichEdit.API.Native;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Diagnostics;
6-
using System.Drawing;
7-
using System.Linq;
8-
using System.Text;
9-
using System.Threading.Tasks;
10-
11-
namespace WordProcessingFileAPI_CalcDocumentVariable
12-
{
13-
class Program
14-
{
15-
static void Main(string[] args)
16-
{
17-
RichEditDocumentServer wordProcessor = new RichEditDocumentServer();
18-
wordProcessor.LoadDocument("Docs\\invitation.docx", DocumentFormat.OpenXml);
19-
20-
Document document = wordProcessor.Document;
21-
//Lock the first field to prevent updates
22-
document.Fields[0].Locked = true;
23-
24-
// Handle the CalculateDocumentVariable event
25-
document.CalculateDocumentVariable += Document_CalculateDocumentVariable;
26-
27-
// Adjust mail-merge options
28-
MailMergeOptions myMergeOptions = document.CreateMailMergeOptions();
29-
myMergeOptions.MergeMode = MergeMode.NewSection;
30-
myMergeOptions.DataSource = new SampleData();
31-
32-
// Handle mail-merge events
33-
wordProcessor.MailMergeRecordStarted += wordProcessor_MailMergeRecordStarted;
34-
wordProcessor.MailMergeRecordFinished += wordProcessor_MailMergeRecordFinished;
35-
36-
// Mail-merge the document
37-
document.MailMerge(myMergeOptions, "Result.docx", DocumentFormat.OpenXml);
38-
39-
Process.Start("Result.docx");
40-
}
41-
42-
private static void Document_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
43-
{
44-
if (e.Arguments.Count > 0)
45-
{
46-
string location = e.Arguments[0].Value.ToString();
47-
if ((location.Trim() == String.Empty) || (location.Contains("<")))
48-
{
49-
e.Value = " ";
50-
e.Handled = true;
51-
return;
52-
}
53-
switch (e.VariableName)
54-
{
55-
case "Weather":
56-
Conditions conditions = new Conditions();
57-
conditions = Weather.GetCurrentConditions(location);
58-
e.Value = String.Format("Weather for {0}: \nConditions: {1}\nTemperature (C) :{2}\nHumidity: {3}\nWind: {4}\n",
59-
location, conditions.Condition, conditions.TempC, conditions.Humidity, conditions.Wind);
60-
break;
61-
case "LOCATION":
62-
if (location == "DO NOT CHANGE!") e.Value = DocVariableValue.Current;
63-
break;
64-
default:
65-
e.Value = "LOCKED FIELD UPDATED";
66-
break;
67-
}
68-
}
69-
else
70-
{
71-
e.Value = "LOCKED FIELD UPDATED";
72-
}
73-
e.Handled = true;
74-
}
75-
76-
private static void wordProcessor_MailMergeRecordStarted(object sender, MailMergeRecordStartedEventArgs e)
77-
{
78-
DocumentRange insertedRange = e.RecordDocument.InsertText(e.RecordDocument.Range.Start, String.Format("Created on {0:G}\n\n", DateTime.Now));
79-
CharacterProperties cp = e.RecordDocument.BeginUpdateCharacters(insertedRange);
80-
cp.FontSize = 8;
81-
cp.ForeColor = Color.Red;
82-
e.RecordDocument.EndUpdateCharacters(cp);
83-
}
84-
85-
private static void wordProcessor_MailMergeRecordFinished(object sender, MailMergeRecordFinishedEventArgs e)
86-
{
87-
e.RecordDocument.AppendDocumentContent("Docs\\bungalow.docx", DocumentFormat.OpenXml);
88-
}
89-
}
90-
}
1+
using DevExpress.XtraRichEdit;
2+
using DevExpress.XtraRichEdit.API.Native;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Diagnostics;
6+
using System.Drawing;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
11+
namespace WordProcessingFileAPI_CalcDocumentVariable
12+
{
13+
class Program
14+
{
15+
static void Main(string[] args)
16+
{
17+
RichEditDocumentServer wordProcessor = new RichEditDocumentServer();
18+
wordProcessor.LoadDocument("Docs\\invitation.docx", DocumentFormat.OpenXml);
19+
20+
Document document = wordProcessor.Document;
21+
//Lock the first field to prevent updates
22+
document.Fields[0].Locked = true;
23+
24+
// Handle the CalculateDocumentVariable event
25+
document.CalculateDocumentVariable += Document_CalculateDocumentVariable;
26+
27+
// Adjust mail-merge options
28+
MailMergeOptions myMergeOptions = document.CreateMailMergeOptions();
29+
myMergeOptions.MergeMode = MergeMode.NewSection;
30+
myMergeOptions.DataSource = new SampleData();
31+
32+
// Handle mail-merge events
33+
wordProcessor.MailMergeRecordStarted += wordProcessor_MailMergeRecordStarted;
34+
wordProcessor.MailMergeRecordFinished += wordProcessor_MailMergeRecordFinished;
35+
36+
// Mail-merge the document
37+
document.MailMerge(myMergeOptions, "Result.docx", DocumentFormat.OpenXml);
38+
var p = new Process();
39+
p.StartInfo = new ProcessStartInfo(@"Result.docx")
40+
{
41+
UseShellExecute = true
42+
};
43+
p.Start();
44+
}
45+
46+
private static void Document_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
47+
{
48+
if (e.Arguments.Count > 0)
49+
{
50+
string location = e.Arguments[0].Value.ToString();
51+
if ((location.Trim() == String.Empty) || (location.Contains("<")))
52+
{
53+
e.Value = " ";
54+
e.Handled = true;
55+
return;
56+
}
57+
switch (e.VariableName)
58+
{
59+
case "Weather":
60+
Conditions conditions = new Conditions();
61+
conditions = Weather.GetCurrentConditions(location);
62+
e.Value = String.Format("Weather for {0}: \nConditions: {1}\nTemperature (C) :{2}\nHumidity: {3}\nWind: {4}\n",
63+
location, conditions.Condition, conditions.TempC, conditions.Humidity, conditions.Wind);
64+
break;
65+
case "LOCATION":
66+
if (location == "DO NOT CHANGE!") e.Value = DocVariableValue.Current;
67+
break;
68+
default:
69+
e.Value = "LOCKED FIELD UPDATED";
70+
break;
71+
}
72+
}
73+
else
74+
{
75+
e.Value = "LOCKED FIELD UPDATED";
76+
}
77+
e.Handled = true;
78+
}
79+
80+
private static void wordProcessor_MailMergeRecordStarted(object sender, MailMergeRecordStartedEventArgs e)
81+
{
82+
DocumentRange insertedRange = e.RecordDocument.InsertText(e.RecordDocument.Range.Start, String.Format("Created on {0:G}\n\n", DateTime.Now));
83+
CharacterProperties cp = e.RecordDocument.BeginUpdateCharacters(insertedRange);
84+
cp.FontSize = 8;
85+
cp.ForeColor = Color.Red;
86+
e.RecordDocument.EndUpdateCharacters(cp);
87+
}
88+
89+
private static void wordProcessor_MailMergeRecordFinished(object sender, MailMergeRecordFinishedEventArgs e)
90+
{
91+
e.RecordDocument.AppendDocumentContent("Docs\\bungalow.docx", DocumentFormat.OpenXml);
92+
}
93+
}
94+
}

‎CS/WordProcessingFileAPI_CalcDocumentVariable/SampleData.cs renamed to ‎CS/SampleData.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
using System.Text;
44
using System.Collections;
55

6-
namespace WordProcessingFileAPI_CalcDocumentVariable
6+
namespace WordProcessingFileAPI_CalcDocumentVariable
77
{
8-
class SampleData : ArrayList
8+
class SampleData : ArrayList
99
{
10-
public SampleData()
10+
public SampleData()
1111
{
1212
Add(new AddresseeRecord("Maria", "Alfreds Futterkiste", "Obere Str. 57, Berlin", "Berlin"));
1313
Add(new AddresseeRecord("Laurence", "Bon app'", "12, rue des Bouchers, Marseille", "Marseille"));
@@ -17,16 +17,16 @@ public SampleData()
1717
}
1818
}
1919

20-
public class AddresseeRecord
20+
public class AddresseeRecord
2121
{
2222
public string Name { get; set; }
2323
public string Company { get; set; }
2424
public string Address { get; set; }
2525
public string City { get; set; }
2626

27-
public AddresseeRecord(string _Name, string _Company, string _Address, string _City)
27+
public AddresseeRecord(string _Name, string _Company, string _Address, string _City)
2828
{
29-
this.Name = _Name;
29+
this.Name = _Name;
3030
this.Company = _Company;
3131
this.Address = _Address;
3232
this.City = _City;
File renamed without changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0-windows</TargetFramework>
4+
<OutputType>Exe</OutputType>
5+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<None Update="Docs\bungalow.docx">
9+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
10+
</None>
11+
<None Update="Docs\invitation.docx">
12+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
13+
</None>
14+
</ItemGroup>
15+
<ItemGroup>
16+
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
17+
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
18+
<PackageReference Include="DevExpress.Document.Processor" Version="24.2.*-*" />
19+
<PackageReference Include="DevExpress.Win.RichEdit" Version="24.2.*-*" />
20+
</ItemGroup>
21+
<ItemGroup>
22+
<Folder Include="Properties\" />
23+
</ItemGroup>
24+
</Project>

‎CS/WordProcessingFileAPI_CalcDocumentVariable.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
VisualStudioVersion = 15.0.28010.2048
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WordProcessingFileAPI_CalcDocumentVariable", "WordProcessingFileAPI_CalcDocumentVariable\WordProcessingFileAPI_CalcDocumentVariable.csproj", "{EAA6C18C-DDD6-4EEC-83C3-14D11FFBFEDB}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WordProcessingFileAPI_CalcDocumentVariable", "WordProcessingFileAPI_CalcDocumentVariable.csproj", "{EAA6C18C-DDD6-4EEC-83C3-14D11FFBFEDB}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution

‎CS/WordProcessingFileAPI_CalcDocumentVariable/App.config

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎CS/WordProcessingFileAPI_CalcDocumentVariable/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

‎CS/WordProcessingFileAPI_CalcDocumentVariable/WordProcessingFileAPI_CalcDocumentVariable.csproj

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /