docx icon indicating copy to clipboard operation
docx copied to clipboard

i want new paragraph(enter) not new lines(shift+enter)

Open Sakarin23479 opened this issue 2 years ago • 4 comments

when add \n in text and then export to docx (\n = pic 1) i'm use paragraph mark for see shift+enter or enter but i need a enter not shift+enter pic 1 shift+enter image pic 2 enter only image

Sakarin23479 avatar Aug 05 '22 13:08 Sakarin23479

@nguyenthenguyen pls help me

Sakarin23479 avatar Aug 05 '22 13:08 Sakarin23479

@Sakarin23479 This is just a simple project for text replacement in DOCX files. If you want to handle the situation you mentioned, it would be necessary to process the content in XML format. It seems that the current project does not have this capability.

NieR4ever avatar Nov 14 '23 07:11 NieR4ever

It's difference between hardline and softline. Maybe this is what you need.

const TAB = "</w:t><w:tab/><w:t>"
const NEWLINE = "</w:t><w:br/><w:t>" //<w:p></w:p>
const HARDLINE = "</w:t><w:p></w:p><w:t>"

func encode(s string) (string, error) {
	var b bytes.Buffer
	enc := xml.NewEncoder(bufio.NewWriter(&b))
	if err := enc.Encode(s); err != nil {
		return s, err
	}
	output := strings.Replace(b.String(), "<string>", "", 1) // remove string tag
	output = strings.Replace(output, "</string>", "", 1)
	output = strings.Replace(output, "&#xD;&#xA;", NEWLINE, -1) // \r\n (Windows newline)
	output = strings.Replace(output, "&#xD;", NEWLINE, -1)      // \r (earlier Mac newline)
	output = strings.Replace(output, "&#xA;", NEWLINE, -1)      // \n (unix/linux/OS X newline)
	output = strings.Replace(output, "&#x1;", HARDLINE, -1)     // \n (unix/linux/OS X newline)
	output = strings.Replace(output, "&#x9;", TAB, -1)          // \t (tab)
	return output, nil
}

hhhcj avatar Mar 04 '24 08:03 hhhcj

I fix this.

hhhcj avatar Mar 04 '24 09:03 hhhcj