Skip to content

Commit

Permalink
feature: ApiTableRowPr.ToJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Yar04ek committed Dec 12, 2023
1 parent a52dbd3 commit b168de4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
29 changes: 29 additions & 0 deletions js/docx/smoke/api_table_row_pr/to_json.js
Original file line number Diff line number Diff line change
@@ -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();
7 changes: 7 additions & 0 deletions spec/docx/smoke/api_table_row_properties_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b168de4

Please sign in to comment.