Telephone D. Gohel 2016-03-25

  • C++ driver close to powerpoint
  • send into xml worksheet
  • entry into java api of reporters
  • fork, cran
  • ggplot color numerical gradient cannot be vector -> ggtools, svg light -> png -> xml, ide update all the document, writexl, xlconnect
  • src, test, R
  • xml unfold
  • reporters low-level architecture


link DrawingML to data in a spreadsheet

DrawingML: Overview

explains differences across document types

main drawingML namespace
<a:graphic> element
DrawingML objects such as charts and diagrams in any document type are all placed within a <a:graphic> element
defines object types such as charts, diagrams, locked canvas, table, ole, etc.; usually undefined; uri attribute which is used to specify the type of data and/or “server” that can process the contents of the element
Spreadsheet > Charts
A chart is placed within a worksheet by a element, which merely references a separate drawing1.xml (or drawing2.xml, etc.) part. Placement or anchoring of the chart is specified with the desired anchor (e.g., element) within the drawing part using the xmlns:xdr="" namespace. The drawing part in turn contains the typical element noted above, which contains a element. That element references a separate part chart1.xml (or chart2.xml, etc) which defines the chart. The namespace (and uri attribute value of ) for the chart specification is xmlns:c="".


  • create simple xlsx file containing line chart created from two numbers
  • write file contents to folder
  • modify files
  • put files back into new zip archive with xlsx file extension

chart object

chart objects

  • xl/chart/chart1.xml
    • [Content_Types].xml: <Override PartName="/xl/charts/chart1.xml" ContentType="application/vnd.openxmlformats-officedocument.drawingml.chart+xml"/>
      • xl/drawings/_rels/drawing1.xml.rels: <Relationship Id="rId1" Type="" Target="../charts/chart1.xml"/>
  • xl/drawing/drawing1.xml
    • [Content_Types].xml: <Override PartName="/xl/drawings/drawing1.xml" ContentType="application/vnd.openxmlformats-officedocument.drawing+xml"/>
      • xl/worksheets/_rels/sheet1.xml.rels: <Relationship Id="rId1" Type="" Target="../drawings/drawing1.xml"/>
  • rId1
    • xl/drawings/drawing1.xml: <c:chart xmlns:c="" xmlns:r="" r:id="rId2"/>

modifications after adding second chart using calc

  • new line for chart2 in [Content_Types].xml and xl/drawings/_rels/drawing1.xml.rels
  • updated dimension of xl/worksheets/sheet1.xml: <dimension ref="A1:B23"/>

adding a third chart without using calc

  • data range: $A$43:$B$44
    • update dimension of xl/worksheets/sheet1.xml: <dimension ref="A1:B44"/> and add to <sheetData>...</sheetData>
    <row r="43" customFormat="false" ht="12.8" hidden="false" customHeight="false" outlineLevel="0" collapsed="false">
      <c r="A43" s="0" t="n">
      <c r="B43" s="0" t="n">
    <row r="44" customFormat="false" ht="12.8" hidden="false" customHeight="false" outlineLevel="0" collapsed="false">
      <c r="A44" s="0" t="n">
      <c r="B44" s="0" t="n">
  • add to drawing1.xml: rId2

<xdr:wsDr ...>
  <xdr:twoCellAnchor editAs="oneCell">
        <xdr:cNvPr id="1" name=""/>
        <a:off x="1236240" y="3449520"/>
        <a:ext cx="5759640" cy="3239640"/>
        <a:graphicData uri="">
          <c:chart xmlns:c="" xmlns:r="" r:id="rId2"/>
  • <a:off ...>: Bounding Box Location and Size:

display file using dropbox website

alternative display

  • Excel Online
  • Microsoft Excel for Android
  • use Gnumeric for interactive navigation through chart layers




functions in R folder

  • addPlot.R
  • 01_tools.R: checkHasSlide()
  • java_description.R: class.DrawingML
  • parProperties.R: .jParProperties()
  • borderNone()
  • borderProperties.R
  • is.color.R
  • colorProperties.R
  • writeDoc.R
docx(), addPlot(), writeDoc()
pptx(), addSlide(), addPlot(), writeDoc()
using R/addSlide.R and R/pptx.graphic.R


write_docx(file = "my_plot.docx", code = print( gg )) does not show graphic in output (tested with LibreOffice writer, Google Drive, Android MS Office compatibility mode)

C++ functions

sourceCpp(file = file.path(dbpath, "GitHub", "rvg", "src", "docx.cpp"))
sourceCpp(file = file.path(dbpath, "GitHub", "rvg", "src", "pptx.cpp"))

differences pptx.cpp, docx.cpp


  • offx, offy
  • obj.p_tag().c_str()
  • fputs(“", pptx_obj->file );
  • fputs(“", pptx_obj->file );
  • fprintf(pptx_obj->file, “%s”, body_pr::a_tag().c_str() );
  • fprintf( pptx_obj->file, “%s”, main_tree::a_closing_tag().c_str() );
  • int i; for(i = 0 ; i < x.size() ; i++ ){ x[i] += pptx_obj->offx; y[i] += pptx_obj->offy; }
  • fputs(“", pptx_obj->file);
  • for(i = 0 ; i < y__.size() ; i++ ){ x__[i] += pptx_obj->offx; y__[i] += pptx_obj->offy; }
  • Rcpp::NumericVector x_(4);
  • y_[1] = y0;
  • x_[2] = x1; y_[2] = y1; x_[3] = x0; y_[3] = y1;
  • xfrm xfrm_(pptx_obj->offx + x -r, pptx_obj->offy + y - r, r * 2, r * 2 , 0.0 );
  • if( fs*100 < 1.0 ) return;
  • double offx, double offy, int pointsize,
  • editable, offx72, offy72, id,


  • obj.wps_tag().c_str()
  • fputs(“", docx_obj->file );
  • fputs(“", docx_obj->file );
  • fputs(“", docx_obj->file );
  • fprintf( docx_obj->file, “%s”, main_tree::w_closing_tag().c_str() );
  • fputs(“", docx_obj->file);
  • Rcpp::NumericVector x_(2);
  • y_[1] = y1;
  • xfrm xfrm_(x - r, y - r, r * 2, r * 2 , 0.0 );
  • if( fs*2 < 1.0 ) return;
  • int pointsize,
  • editable, id,

lines 680-714


fputs(“", pptx_obj->file);

fputs("<p:nvPicPr>", pptx_obj->file);
    "<p:cNvPr id=\"%d\" name=\"pic%d\"/>",
    idx, idx );
  fputs("<p:cNvPicPr/>", pptx_obj->file);
  fputs("<p:nvPr/>", pptx_obj->file);
fputs("</p:nvPicPr>", pptx_obj->file);
fputs("<p:blipFill>", pptx_obj->file);
  "<a:blip r:embed=\"rId%d\" cstate=\"print\"/>",
fputs("<a:stretch><a:fillRect/></a:stretch>", pptx_obj->file);
fputs("</p:blipFill>", pptx_obj->file);

fputs("<p:spPr>", pptx_obj->file);

fprintf(pptx_obj->file, "%s", xfrm_.xml().c_str());

fprintf(pptx_obj->file,"%s", a_prstgeom::a_tag("rect").c_str());

fputs("</p:spPr>", pptx_obj->file);

fputs(“</p:pic>”, pptx_obj->file);


fputs(“", docx_obj->file); write_nv_pr_docx(dd, "rs");

fputs(“", docx_obj->file);

fprintf(docx_obj->file, “%s”, xfrm_.xml().c_str());

fprintf(docx_obj->file,”%s”, a_prstgeom::a_tag(“rect”).c_str()); fputs(“<a:blipFill rotWithShape="1">”, docx_obj->file); fprintf(docx_obj->file, “<a:blip r:embed="rId%d"/>”, id_img_rel); fputs(“”, docx_obj->file); fputs(“</a:blipFill>”, docx_obj->file); fprintf(docx_obj->file, “%s”, line_style_.a_tag().c_str());

fputs(“</wps:spPr>”, docx_obj->file); fprintf(docx_obj->file, “%s”,empty_body_text::wps_tag().c_str());

fputs(“</wps:wsp>”, docx_obj->file);


30 March 2016