We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Docx created by WPS replace something using Aspose.Words ,the line spacing has been change

I have a docx file that created by WPS,When i replace something using Aspose.Words,the line spacing has been change.
the version is Aspose.Words for .Net 20.12.0.0.
20211216215514.png (4.3 KB)

the oragin file
demo.docx (10.8 KB)

the file has been processed
processed.docx (10.0 KB)

@sullivan,
Unfortunately, we were unable to reproduce the same issue on our side. On my side, the line spacing in your input and output documents are the same, when opened using MS Word.
Please note that Aspose.Words mimics the behavior of MS Word. The text formatting may look different in other applications.

unable to reproduce the same issue ? You can try run code like this:

string inputPath = @"C:\Users\sullivan\Desktop\demo.docx";
string outPath = @"C:\Users\sullivan\Desktop\outputfile.docx";
var doc = new Aspose.Words.Document(inputPath);
doc.Save(outPath);

the line spacing of outputfile has been changed

@sullivan,
Please check the following screenshot with compared input document and output document I got:

We suggest you please use the MS Word to view the documents. The documents may look different, if opened with WPS Office.

@sullivan The problem occur because WPS Office does not write paragraph spacing defaults into the document. You can unzip input and output document, open styles.xml and you will see the following:
source

	<w:docDefaults>
		<w:rPrDefault>
			<w:rPr>
				<w:rFonts w:asciiTheme="minorHAnsi" w:hAnsiTheme="minorHAnsi" w:eastAsiaTheme="minorEastAsia" w:cstheme="minorBidi"/>
			</w:rPr>
		</w:rPrDefault>
	</w:docDefaults>

output

	<w:docDefaults>
		<w:rPrDefault>
			<w:rPr>
				<w:rFonts w:asciiTheme="minorHAnsi" w:eastAsiaTheme="minorEastAsia" w:hAnsiTheme="minorHAnsi" w:cstheme="minorBidi" />
				<w:lang w:val="en-US" w:eastAsia="en-US" w:bidi="ar-SA" />
			</w:rPr>
		</w:rPrDefault>
		<w:pPrDefault>
			<w:pPr>
				<w:spacing w:after="160" w:line="259" w:lineRule="auto" />
			</w:pPr>
		</w:pPrDefault>
	</w:docDefaults>

As you can see in the source document there is no pPrDefault element. It seems WPS Office has these defaults hardcoded or defined in it’s templates.
Aspose.Words in this case mimics MS Word behavior and writes the missed defaults into the output document. You can change the defaults programmatically to make the document look the same as in WPS Office. For example see the following code:

Document doc = new Document(@"C:\Temp\demo.docx");
doc.Styles.DefaultParagraphFormat.SpaceAfter = 0;
doc.Save(@"C:\Temp\out.docx");

I am not sure zero is correct value, but it seems it is what you see in WPS Office.