-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
builder.CreateFile("docx"); | ||
var oDocument = Api.GetDocument(); | ||
CustomDefaultStyle(oDocument) | ||
var oBlockLvlSdt = Api.CreateBlockLvlSdt(); | ||
oBlockLvlSdt.SetAlias("№1"); | ||
var oBlockContent = oBlockLvlSdt.GetContent() | ||
oBlockContent.GetElement(0).AddText("blockLvlSdt"); | ||
var oNumbering = oDocument.CreateNumbering("bullet"); | ||
for (let nLvl = 0; nLvl < 8; ++nLvl) { | ||
var oNumLvl = oNumbering.GetLevel(nLvl); | ||
var oParagraph = Api.CreateParagraph(); | ||
oParagraph.AddText("Default bullet lvl " + (nLvl + 1)); | ||
oParagraph.SetNumbering(oNumLvl); | ||
oParagraph.SetContextualSpacing(true); | ||
oBlockContent.Push(oParagraph); | ||
} | ||
var json = oBlockLvlSdt.ToJSON(true, true); | ||
function CustomDefaultStyle(oDocument){ | ||
var oNormalStyle = oDocument.GetDefaultStyle("paragraph"); | ||
var oTextPr = oNormalStyle.GetTextPr(); | ||
oTextPr.SetColor(0x26, 0x26, 0x26, false); | ||
oTextPr.SetFontFamily("Calibri Light"); | ||
oTextPr.SetFontSize(32); | ||
} | ||
GlobalVariable["JSON"] = json; | ||
builder.CloseFile(); | ||
|
||
//////////////////////// | ||
|
||
builder.CreateFile("docx"); | ||
var json = GlobalVariable["JSON"]; | ||
var oDocument = Api.GetDocument(); | ||
var oParagraph = oDocument.GetElement(0); | ||
oParagraph.AddText(json) | ||
var oBlockSdtFromJSON = Api.FromJSON(json); | ||
oDocument.AddElement(0, oBlockSdtFromJSON); | ||
builder.SaveFile("docx", "ToJSON.docx"); | ||
builder.CloseFile(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'ApiBlockLvlSdt section tests' do | ||
it 'ApiBlockLvlSdt | ToJSON method' do | ||
docx = builder.build_and_parse('js/docx/smoke/api_block_lvl_sdt/to_json.js') | ||
expect(docx.elements[0].sdt_content.elements[0].character_style_array[1].text).to eq('blockLvlSdt') | ||
expect(docx.elements[0].sdt_content.elements[8].numbering.i_level.value).to eq(7) | ||
json = JSON.parse(docx.elements[1].nonempty_runs.first.text) | ||
expect(json['type']).to eq('blockLvlSdt') | ||
expect(json['numbering']['type']).to eq('numbering') | ||
end | ||
end |