Home » excel » c# – Excel XML Spreadsheet CSHTML

c# – Excel XML Spreadsheet CSHTML

Posted by: admin May 14, 2020 Leave a comment


I want to create a graph in Excel with the spreadsheet reference.

@model IEnumerable<ARTex.Core.Models.Reservation>

    Layout = null;
    Response.ContentType = "application/vnd.ms-excel";
    Response.AddHeader("Content-Disposition", "attachment; filename= Reservaties - " + DateTime.Now.ToString("dd/MM/yyyy") + ".xls");


    <?xml version="1.0" encoding="utf-16"?>

<ss:Workbook xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
        <!--style reservation header-->
        <ss:Style ss:ID="1">
            <ss:Font ss:Bold="1" ss:Size="11" ss:Color="White"/>
            <ss:Interior ss:Color='Black'  ss:Pattern='Solid'/>
        <!--style group/individual header-->
        <ss:Style ss:ID="2">
            <ss:Font ss:Bold="1" ss:Size="11"/>
            <ss:Interior ss:Color='#D9D9D9' ss:Pattern='Solid'/>
        <!--style group/individual/reservation body-->
        <ss:Style ss:ID="3">
            <ss:Interior ss:Pattern='Solid' />
            <ss:Alignment ss:WrapText="1" ss:Vertical="Top"/>
        <ss:Style ss:ID="4">
            <ss:Interior ss:Pattern='Solid'/>

@{Html.RenderPartial("_ExcelWorksheet", Model.Where(x => !x.Deleted), new ViewDataDictionary { { "sheetName", "Reservations" } });
  Html.RenderPartial("_ExcelWorksheet", Model.Where(x => x.Deleted), new ViewDataDictionary { { "sheetName", "Deleted Reservations" } });
  Html.RenderPartial("_ExcelGraph", Model,new ViewDataDictionary{ {"sheetname", "Graph" }});}}


this is my main .cshtml page and I want to create a graph with the Partial view page _ExcelGraph. I’m just trying to show the some basic output.

Code _ExcelGraph


    var myChart = new Chart(width: 600, height: 400) 
        .AddTitle("Chart Title") 
            name: "Employee", 
            xValue: new[] {  "Peter", "Andrew", "Julie", "Mary", "Dave" }, 
            yValues: new[] { "2", "6", "4", "5", "3" }) 

This keeps giving me an image and I can’t seem to figure out how to place this image in a worksheet or how I can properly show it as a worksheet.

Thanks in advance.


Read somewhere that this ain’t possible with XML spreadsheet reference 2003 ?

How to&Answers:

You cannot embed Charts in XML Spreadsheet 2003.