Hi,
The following C# code, in linqpad, can be executed successfully, It supports the following picture formats,This is convenient
![[Image: bbbb.png]](https://i.ibb.co/BLD3fSw/bbbb.png)
But when I copy the code into the LA, there will be a hint in the picture below, where the red box part is the wrong hint
![[Image: a.png]](https://i.ibb.co/Ky85r7W/a.png)
If I click the Yes button, I need to manually delete these erroneous items
I suggest that LA can support the format of the picture below, do not pop up the prompt (Don't put using code in top comments)
![[Image: abc.png]](https://i.ibb.co/6DFhP29/abc.png)
After I made the modification, I executed the code and still reported an error, maybe that using the main method directly is not supported
![[Image: ac.png]](https://i.ibb.co/KLhbvyc/ac.png)
It seems that copying code to LA from Linqpad is not very convenient and requires a lot of modifications
The following C# code, in linqpad, can be executed successfully, It supports the following picture formats,This is convenient
![[Image: bbbb.png]](https://i.ibb.co/BLD3fSw/bbbb.png)
But when I copy the code into the LA, there will be a hint in the picture below, where the red box part is the wrong hint
![[Image: a.png]](https://i.ibb.co/Ky85r7W/a.png)
If I click the Yes button, I need to manually delete these erroneous items
I suggest that LA can support the format of the picture below, do not pop up the prompt (Don't put using code in top comments)
![[Image: abc.png]](https://i.ibb.co/6DFhP29/abc.png)
After I made the modification, I executed the code and still reported an error, maybe that using the main method directly is not supported
![[Image: ac.png]](https://i.ibb.co/KLhbvyc/ac.png)
It seems that copying code to LA from Linqpad is not very convenient and requires a lot of modifications
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
static void Main(string[] args)
{
Environment.CurrentDirectory = @"C:\Users\Administrator\Desktop";
Document doc = new Document();
doc.LoadFromFile(@"Test2b.docx");
foreach (Section section in doc.Sections)
{
foreach (Paragraph paragraph in section.Body.Paragraphs)
{
if (paragraph.StyleName != "Heading1")
{
HashSet<float> fontSize = new HashSet<float>();
HashSet<Color> fontColor = new HashSet<Color>();
foreach (DocumentObject paraChildObject in paragraph.ChildObjects)
{
if (paraChildObject.DocumentObjectType == DocumentObjectType.TextRange)
{
TextRange textRange = paraChildObject as TextRange;
Font font = textRange.CharacterFormat.Font;
fontSize.Add(font.Size);
Color color = textRange.CharacterFormat.TextColor;
fontColor.Add(color);
if (font.Name == "kaiti")
{
textRange.CharacterFormat.Font = new Font("liti", font.Size);
}
}
}
if (fontSize.Count > 1)
{
setA(paragraph);
}
}
}
}
doc.SaveToFile(@"result.docx", FileFormat.Docx);
}
public static void setA(Paragraph para)
{
para.Format.BeforeSpacing = 8f;
para.Format.AfterSpacing = 16f;
para.Format.LineSpacing = 16f;
para.Format.LineSpacingRule = LineSpacingRule.Exactly;
foreach (DocumentObject paraChildObject in para.ChildObjects)
{
if (paraChildObject.DocumentObjectType == DocumentObjectType.TextRange)
{
TextRange textRange = paraChildObject as TextRange;
if (Regex.IsMatch(textRange.Text, "^([A-Za-z]){1}[^.]*."))
{
textRange.CharacterFormat.Font = new Font("Consolas", 14);
}
if (Regex.IsMatch(textRange.Text, "^[\u4e00-\u9fbb]+"))
{
textRange.CharacterFormat.Font = new Font("宋体", 14);
}
}
}
}