Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
155
Load Workbook created in C# Excel Engine
posted

I have created a workbook using the c# infragistics excel engine, I have tried several methods to populate the igSpreadsheet with the workbook.

my Controller:

public void GetReport()
   {
                    var test= ReportHelper.GetRentRollExcel(new RentRollExcel
               {
                   CurrentDatePicker =  DateTime.UtcNow,
                   Id = 9,
                   SendForDownload = false
               }, _db, Server.MapPath("~"), Url, false);
 
       Response.Clear();
       Response.AppendHeader("content-disposition""attachment; filename=" + test.FileName);
       Response.ContentType = "application/octet-stream";
       test.Workbook.Save(Response.OutputStream);
       Response.End();
   }
  

 public FileContentResult GetReport2()
   {
 
 
       MemoryStream fs = new MemoryStream();
       var test = ReportHelper.GetRentRollExcel(new RentRollExcel
       {
           CurrentDatePicker = DateTime.UtcNow,
           Id = 9,
           SendForDownload = false
       }, _db, Server.MapPath("~"), Url, false);
 
      
       test.Workbook.Save(fs);
 
       return new FileContentResult(fs.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
 
   }

public string GetReport3()
     {
 
 
         MemoryStream fs = new MemoryStream();
         var test = ReportHelper.GetRentRollExcel(new RentRollExcel
         {
             CurrentDatePicker = DateTime.UtcNow,
             Id = 9,
             SendForDownload = false
         }, _db, Server.MapPath("~"), Url, false);
 
 
         test.Workbook.Save(fs);
         return BitConverter.ToString(fs.ToArray());
         return Convert.ToBase64String(fs.ToArray());
         
     }

Obviously I have tried different ways to accomplish this: In the Java Script I have:

tried the following:

         $.ig.loader({
        scriptPath: "/Scripts/Infragistics/",
        cssPath: "/Content/InfragisticsCSS/css",
        resources: "igSpreadsheet, igExcel.LoadSaveXlsx, igExcel.LoadSaveXls, igExcel.Functions",
        ready: function() {
                    //Initializing igSpreadsheet
            $("#spreadsheet").igSpreadsheet({
                height: "600",
                width: "100%",
                isFormulaBarVisible: false,
                allowAddWorksheet: false,
                allowDeleteWorksheet: false
            });
            var workbook = null;
            var xhr = new XMLHttpRequest();
            xhr.open('GET''@Url.Action("GetReport3""Reports")'true);
            xhr.responseType = 'blob';
 
            xhr.onload = function (e) {
                        // response is unsigned 8 bit integer
 
                var fileReader = new FileReader();
 
 
                fileReader.onload = function (e) {
 
                  
                    var buffer = new Uint8Array(fileReader.result);
                    $.ig.excel.Workbook.load(buffer,
                        function(arg) {
                            workbook = arg;
                            setInitialSettings();
                        },
                        function() {
                            console.log("fail");
                        });
                }
                fileReader.readAsArrayBuffer(this.response);
 
 
            };
            xhr.send();
 
        }
    });
 
 
    $('#CompanyEntityId').selectize();
 
 
})

//Another ATTEMPT
          $.ig.loader({
              scriptPath: "/Scripts/Infragistics/",
              cssPath: "/Content/InfragisticsCSS/css",
              resources: "igSpreadsheet, igExcel.LoadSaveXlsx, igExcel.LoadSaveXls, igExcel.Functions",
              ready: function() {
                    //Initializing igSpreadsheet
                  $("#spreadsheet").igSpreadsheet({
                      height: "600",
                      width: "100%",
                      isFormulaBarVisible: false,
                      allowAddWorksheet: false,
                      allowDeleteWorksheet: false
                  });
                  var workbook = null;
                  var xhr = new XMLHttpRequest();
                  xhr.open('GET''@Url.Action("GetReport""Reports")'true);
                  xhr.responseType = 'blob';
 
                  xhr.onload = function(e) {
                        // response is unsigned 8 bit integer
 
                      var fileReader = new FileReader();
 
 
                      fileReader.onload = function(e) {
                          var buffer = new Uint8Array(fileReader.result);
                          $.ig.excel.Workbook.load(fileReader.result,
                              function(arg) {
                                  workbook = arg;
                                  setInitialSettings();
                              },
                              function() {
                                  console.log("fail");
                              });
                      }
                      fileReader.readAsArrayBuffer(this.response);
 
 
                  };
                  xhr.send();
 
              }
          });
 
 
          $('#CompanyEntityId').selectize();
 
 
      });

            //Another ATTEMPT
    $.ig.loader({
        scriptPath: "/Scripts/Infragistics/",
        cssPath: "/Content/InfragisticsCSS/css",
        resources: "igSpreadsheet, igExcel.LoadSaveXlsx, igExcel.Functions",
        ready: function() {
                    //Initializing igSpreadsheet
            $("#spreadsheet").igSpreadsheet({
                height: "600",
                width: "100%",
                isFormulaBarVisible: false,
                allowAddWorksheet: false,
                allowDeleteWorksheet: false
            });
 
            $.ajax({
                url: '@Url.Action("GetReport3","Reports")',
              
                success: function(data) {
                    var responseArray = new Uint8Array(data);
                    var book = $.ig.excel.Workbook.load(data,
                        function(err, workbook) {
                            workbook = arguments[0];
                           
                        },
                        function() {
                            console.log("fail");
                        });
 
                    $("#spreadsheet").igSpreadsheet("option""workbook", workbook);
                },
                error: function() {
                    createError('errorMessage''type');
                },
                complete: function() {
 
                }
            });
 
        }
    });
 
 
    $('#CompanyEntityId').selectize();
 
 
});

I either get one of two messages:

or 




****UPDATE****
It appears that the problem lies with Merged Cells You can Merge cells but when you add any value to them, Borders,fills,text, formulas the IgSpreadsheet will not read them.

excel file.zip
Parents
  • 4315
    Offline posted

    Hello, Landrum.

    As far as I understand, you are saying that when loading an excel file that has merged cells (that have border, fill, etc.) the igSpreadsheet is not visualizing them properly? Correct me if I'm wrong. This is functionality that is expecting to work. I see you are using the example from our samples browser. I took the following sample and just add a merged cell to the excel file and the igSpreadsheet is properly visualizing the cell, together with all its modifications.

    Is this the only problem you are experiencing right now? I also cannot see the error images that you have uploaded. Please share more details about the errors you are seeing and I will help you further. Thank you in advance for cooperation!

    Best regards,

    Nikolay Alipiev,

    Software Developer

    Infragistics

Reply Children