diff --git a/js/docx/smoke/api_table_row_pr/to_json.js b/js/docx/smoke/api_table_row_pr/to_json.js new file mode 100644 index 00000000..727a9193 --- /dev/null +++ b/js/docx/smoke/api_table_row_pr/to_json.js @@ -0,0 +1,29 @@ +builder.CreateFile("docx"); + let oDocument = Api.GetDocument(); + let oParagraph = oDocument.GetElement(0); + let oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table"); + oTableStyle.SetName("My Custom Table Style"); + let oTableRowPr = oTableStyle.GetTableRowPr(); + oTableRowPr.SetHeight("atLeast", 720); + let jsonTableStyle = oTableStyle.ToJSON(); + GlobalVariable["JSON_TableStyle"] = jsonTableStyle; + oParagraph.AddText(jsonTableStyle); +builder.CloseFile(); + +////////////// + +builder.CreateFile("docx"); + let oDocument = Api.GetDocument(); + let oParagraph = oDocument.GetElement(0); + let jsonTableStyle = GlobalVariable["JSON_TableStyle"]; + oParagraph.AddText(jsonTableStyle); + let oTableStyle = oDocument.GetStyle("My Custom Table Style"); + let oTable = Api.CreateTable(3, 3); + oTable.SetStyle(oTableStyle); + oDocument.Push(oTable); + let jsonTable = oTableStyle.ToJSON(); + let oParagraph2 = Api.CreateParagraph(); + oDocument.Push(oParagraph2); + oParagraph2.AddText(jsonTable); +builder.SaveFile("docx", "TableStyleToJSON.docx"); +builder.CloseFile(); diff --git a/spec/docx/smoke/api_table_row_properties_spec.rb b/spec/docx/smoke/api_table_row_properties_spec.rb index b455dc31..beb913dd 100644 --- a/spec/docx/smoke/api_table_row_properties_spec.rb +++ b/spec/docx/smoke/api_table_row_properties_spec.rb @@ -16,4 +16,11 @@ docx = builder.build_and_parse('js/docx/smoke/api_table_row_pr/set_table_header.js') expect(docx.elements[1].properties.table_style.table_row_properties.table_header).to be_truthy end + + it 'ApiTableRowPr | ToJson method' do + docx = builder.build_and_parse('js/docx/smoke/api_table_row_pr/to_json.js') + json = docx.elements[0].nonempty_runs.map(&:text).join + parsed_json = JSON.parse(json) + expect(parsed_json).to include('name' => 'My Custom Table Style') + end end