XML : Transforming xslt into SpreedsheetDocument

I'm currently working on a project where I'm taking an older style report that was generated in an RDLC and converting it over to being build via OpenXml. I had been building the report by hand but it was suggested I do so with xslt instead due to styling issues.

So far, below is my xslt for the first page.

  <xsl:stylesheet       version="1.0"       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:xs="http://www.w3.org/2001/XMLSchema"       xmlns:n2="urn:hl7-org:v3"       exclude-result-prefixes="n2 xs xsi xsl"       >    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>    <xsl:template match="/">      <workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"        xmlns:o="urn:schemas-microsoft-com:office:office"        xmlns:x="urn:schemas-microsoft-com:office:excel"        xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"        xmlns:html="http://www.w3.org/TR/REC-html40">        <worksheet ss:Name="Goal"          xmlns:cdr="http://schemas.openxmlformats.org/drawingml/2006/chartDrawing"          xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"          xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"          xmlns:s="http://schemas.openxmlformats.org/officeDocument/2006/sharedTypes"          xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"          xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"          xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">          <sheetPr>            <outlinePr/>          </sheetPr>          <sheetViews>            <sheetView showGridLines="0" workbookViewId="0"/>          </sheetViews>          <cols>            <col width="0.15234375" customWidth="1" max="1" min="1"/>            <col width="6.5234375" customWidth="1" max="2" min="2"/>            <col width="7.421875" customWidth="1" max="3" min="3"/>            <col width="6.6328125" customWidth="1" max="4" min="4"/>            <col width="4.8515625" customWidth="1" max="5" min="5"/>            <col width="84.5234375" customWidth="1" max="6" min="6"/>            <col width="11.53125" customWidth="1" max="7" min="7"/>            <col width="0.0234375" customWidth="1" max="8" min="8"/>            <col width="0.40234375" customWidth="1" max="9" min="9"/>            <col width="0.0234375" customWidth="1" max="10" min="10"/>            <col width="0.15234375" customWidth="1" max="11" min="11"/>            <col width="28.51171875" customWidth="1" max="12" min="12"/>          </cols>          <sheetData>            <row r="1" customHeight="1" ht="25.25"/>            <row r="2" customHeight="1" ht="18">              <c s="1" r="A2" t="inlineStr">                <is>                  <t xml:space="preserve"><xsl:value-of select="GoalDS/@GoalReportName" /></t>                </is>              </c>            </row>            <row r="3" customHeight="1" ht="2"/>            <row r="4" customHeight="1" ht="19.45">              <c s="2" r="A4" t="inlineStr">                <is>                  <t xml:space="preserve"><xsl:value-of select="GoalDS/@ReportTypeDesc" /></t>                </is>              </c>            </row>            <row r="5" customHeight="1" ht="5.05"/>            <row r="6" customHeight="1" ht="18">              <c s="1" r="A6" t="inlineStr">                <is>                  <t xml:space="preserve">Fossil Energy Coal &amp; Power RD&amp;D Portfolio</t>                </is>              </c>            </row>            <row r="7" customHeight="1" ht="125.5"/>            <row r="8" customHeight="1" ht="67.5">              <c s="3" r="A8" t="inlineStr">                <is>                  <t xml:space="preserve"><xsl:value-of select="GoalDS/@GoalDescription"/></t>                </is>              </c>            </row>            <row r="9" customHeight="1" ht="3"/>            <row r="10" customHeight="1" ht="15.75">              <c s="4" r="A10" t="inlineStr">                <is>                  <t xml:space="preserve">DOE Mission - Discovering the solutions to power and secure America's future</t>                </is>              </c>              <c s="5" r="B10" t="str"/>              <c s="5" r="C10" t="str"/>              <c s="5" r="D10" t="str"/>              <c s="5" r="E10" t="str"/>              <c s="5" r="F10" t="str"/>              <c s="5" r="G10" t="str"/>              <c s="5" r="H10" t="str"/>              <c s="6" r="I10" t="str"/>            </row>            <row r="11" customHeight="1" ht="1"/>            <row r="12" customHeight="1" ht="16.95">              <c s="4" r="B12" t="inlineStr">                <is>                  <t xml:space="preserve">DOE Strategic Theme 1: </t>                </is>              </c>              <c s="5" r="C12" t="str"/>              <c s="5" r="D12" t="str"/>              <c s="5" r="E12" t="str"/>              <c s="5" r="F12" t="str"/>              <c s="5" r="G12" t="str"/>              <c s="5" r="H12" t="str"/>              <c s="5" r="I12" t="str"/>              <c s="5" r="J12" t="str"/>              <c s="6" r="K12" t="str"/>            </row>            <row r="13" customHeight="1" ht="2.05"/>            <row r="14" customHeight="1" ht="16.2">              <c s="4" r="C14" t="inlineStr">                <is>                  <t xml:space="preserve">Goal 1.2 - Environmental Impacts of Energy:</t>                </is>              </c>              <c s="5" r="D14" t="str"/>              <c s="5" r="E14" t="str"/>              <c s="5" r="F14" t="str"/>              <c s="5" r="G14" t="str"/>              <c s="5" r="H14" t="str"/>              <c s="6" r="I14" t="str"/>            </row>            <row r="15" customHeight="1" ht="1.05"/>            <row r="16" customHeight="1" ht="15.5">              <c s="4" r="D16" t="inlineStr">                <is>                  <t xml:space="preserve"><xsl:value-of select="GoalDS/@ReportTypeDesc"/></t>                </is>              </c>              <c s="5" r="E16" t="str"/>              <c s="5" r="F16" t="str"/>              <c s="5" r="G16" t="str"/>              <c s="5" r="H16" t="str"/>              <c s="6" r="I16" t="str"/>            </row>            <row r="17" customHeight="1" ht="1"/>            <xsl:for-each select="Report/TechAreaDS">              <row customHeight="1" ht="12.8">                <c s="7" t="inlineStr">                  <is>                    <t xml:space="preserve"><xsl:value-of select="@TechAreaName"/></t>                  </is>                </c>                <c s="5" t="str"/>                <c s="5" t="str"/>                <c s="5" t="str"/>                <c s="6" t="str"/>              </row>            </xsl:for-each>            <row customHeight="1" ht="0.05"/>            <row customHeight="1" ht="2"/>            <row customHeight="0" ht="18">              <c s="7" t="inlineStr">                <is>                  <t xml:space="preserve"><xsl:value-of select="CountDS/@HeadingCountOfMeasures"/></t>                </is>              </c>              <c s="8">                <v><xsl:value-of select="CountDS/@CountOfMeasures"/></v>              </c>            </row>            <row customHeight="0" ht="18">              <c s="7" t="inlineStr">                <is>                  <t xml:space="preserve"><xsl:value-of select="CountDS/@HeadingCountOfMilestones"/></t>                </is>              </c>              <c s="8">                <v><xsl:value-of select="CountDS/@CountOfMilestones"/></v>              </c>            </row>          </sheetData>          <mergeCells>            <mergeCell ref="A2:I2"/>            <mergeCell ref="A4:I4"/>            <mergeCell ref="A6:I6"/>            <mergeCell ref="A8:I8"/>            <mergeCell ref="A10:I10"/>            <mergeCell ref="B12:K12"/>            <mergeCell ref="C14:I14"/>            <mergeCell ref="D16:I16"/>            <mergeCell ref="E18:I18"/>            <!--<mergeCell ref="E19:I19"/>            <mergeCell ref="E20:I20"/>-->          </mergeCells>          <pageMargins footer="0.5" header="0.5" bottom="0.5" top="0.5" right="0.75" left="0.75"/>          <pageSetup verticalDpi="300" horizontalDpi="300" orientation="landscape"/>          <headerFooter alignWithMargins="0"/>        </worksheet>      </workbook>    </xsl:template>  </xsl:stylesheet>    

My question is, how do I transform my xslt into something usable by OpenXml in C#? This is what I have thus far, but am unsure on how to proceed any further because all I'm getting right now are errors that the sheet1.xml cannot be found.

  public byte[] GetGPRA_ARRA_FA_Qtr_Report(int fiscalYear, string reportType, int officeId, out string mimeType)          {              mimeType = string.Empty;              byte[] buffer = null;                #region Create File Path, File Name, and temporary directory              var path = ConfigurationProperties.WorkingDirectoryPath;              // create a new guid for the current document (we will delete this path at the end)              var tempLocation = Guid.NewGuid();              path = Path.Combine(path, tempLocation.ToString());              // create the working assembly folder              if (!Directory.Exists(path))                  Directory.CreateDirectory(path);                if (!TransformXmlToOpenXml(GetQuarterlyReportXml(fiscalYear, reportType, officeId), path))              {                  // delete the working folder first and return null                  if (!ConfigurationProperties.DebugWorkingFileOutput)                      Directory.Delete(path, true);                  return null;              }                //Set the filename to the Report Type              var fileName = Path.Combine(path, (reportType + " Quarterly Report.xlsx"));              var workbookXml = Path.Combine(path, "workbook.xml");              var mainDoc = new XmlDocument();              mainDoc.Load(workbookXml);              

No comments:

Post a Comment