Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Tracking changes in Paragraph #320

Open
devarsh opened this issue Sep 5, 2019 · 1 comment
Open

Support for Tracking changes in Paragraph #320

devarsh opened this issue Sep 5, 2019 · 1 comment

Comments

@devarsh
Copy link

devarsh commented Sep 5, 2019

Description

I was going through the properties in Paragraph but there is no property in the structure to add <w:ins> and <w:del> child property and then add run to those properties like how MS Word keeps tracks of text changes in the word document.

Below is the code snippet and the generated output and the output generated from Microsoft word.

func main() {
	doc := document.New()
	doc.Settings.X().TrackRevisions = wml.NewCT_OnOff()
	para := doc.AddParagraph()
	doc.AddParagraph()
	run := para.AddRun()
	run.AddText("I am working at")
	AddOldValue(&para, "Yahoo", "00475D3C", 0)
	AddNewValue(&para, "Google", "00475D3C", 1)
	doc.SaveToFile("demo.docx")
}

func AddNewValue(p *document.Paragraph, newVal string, revNum string, id int64) {
	exprops := p.Properties().X()
	pprChange := wml.NewCT_PPrChange()
	exprops.PPrChange = pprChange
	pprChange.AuthorAttr = "Devarsh"
	t := time.Now()
	pprChange.DateAttr = &t
	pprChange.IdAttr = id
	run := p.AddRun()
	run.X().RsidDelAttr = &revNum
	ic := wml.NewEG_RunInnerContent()
	run.X().EG_RunInnerContent = append(run.X().EG_RunInnerContent, ic)
	ic.InstrText = wml.NewCT_Text()
	ic.InstrText.Content = newVal
}

func AddOldValue(p *document.Paragraph, oldVal string, revNum string, id int64) {
	exprops := p.Properties().X()
	pprChange := wml.NewCT_PPrChange()
	exprops.PPrChange = pprChange
	pprChange.AuthorAttr = "Devarsh"
	t := time.Now()
	pprChange.DateAttr = &t
	pprChange.IdAttr = id
	run := p.AddRun()
	run.X().RsidDelAttr = &revNum
	ic := wml.NewEG_RunInnerContent()
	run.X().EG_RunInnerContent = append(run.X().EG_RunInnerContent, ic)
	ic.DelText = wml.NewCT_Text()
	ic.DelText.Content = oldVal
}

Output :

<w:body>
    <w:p>
      <w:pPr>
        <w:pPrChange w:author="Devarsh" w:date="2019-09-06 02:05:53.786744 +0530 IST m=+0.002038602" w:id="1">
          <w:pPr/>
        </w:pPrChange>
      </w:pPr>
      <w:r>
        <w:t>I was working at</w:t>
      </w:r>
      <w:r w:rsidDel="00475D3C">
        <w:delText>Yahoo</w:delText>
      </w:r>
      <w:r w:rsidDel="00475D3C">
        <w:instrText>Google</w:instrText>
      </w:r>
    </w:p>
    <w:p/>
  </w:body>

Expected Behavior

Output of Ms Word file generated

<w:body>
    <w:p w14:paraId="40657538" w14:textId="59AD6A02" w:rsidR="00984CD3" w:rsidRPr="00AC36C7" w:rsidRDefault="00AC36C7">
      <w:pPr>
        <w:rPr>
          <w:lang w:val="en-US"/>
        </w:rPr>
      </w:pPr>
      <w:r>
        <w:rPr>
          <w:lang w:val="en-US"/>
        </w:rPr>
        <w:t xml:space="preserve">I was working with </w:t>
      </w:r>
      <w:del w:id="0" w:author="Devarsh Shah" w:date="2019-09-06T02:09:00Z">
        <w:r w:rsidDel="002773B1">
          <w:rPr>
            <w:lang w:val="en-US"/>
          </w:rPr>
          <w:delText>Yahoo!</w:delText>
        </w:r>
      </w:del>
      <w:ins w:id="1" w:author="Devarsh Shah" w:date="2019-09-06T02:09:00Z">
        <w:r w:rsidR="002773B1">
          <w:rPr>
            <w:lang w:val="en-US"/>
          </w:rPr>
          <w:t>google!</w:t>
        </w:r>
      </w:ins>
      <w:bookmarkStart w:id="2" w:name="_GoBack"/>
      <w:bookmarkEnd w:id="2"/>
    </w:p>
@gunnsth gunnsth added the feature New feature label Sep 20, 2019
@gunnsth gunnsth added this to Document in Issue Overview Nov 18, 2019
@compleatang
Copy link
Contributor

++ to this feature request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

3 participants