Unable to modify Excel from ASP.NET CORE2019 Community Moderator ElectionHow to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How do I properly clean up Excel interop objects?Collection was modified; enumeration operation may not executeGet int value from enum in C#Error - Unable to access the IIS metabaseASP.NET Core MVC (former MVC 6) Razor errors not getting caught by exception filterHow to dispose of Serilog 2.0 correctly in ASP.NET Core application?How to reference an ASP.NET Core project from a Full .Net framework Test project?System.IdentityModel.Metadata and X509SecurityToken not available in ASP.NET CoreASP.Net Core application can't find Microsoft.ApplicationBlocks.Data assembly

What does it mean to make a bootable LiveUSB?

Good allowance savings plan?

How to write cleanly even if my character uses expletive language?

Russian cases: A few examples, I'm really confused

How do anti-virus programs start at Windows boot?

What has been your most complicated TikZ drawing?

What are the possible solutions of the given equation?

Current sense amp + op-amp buffer + ADC: Measuring down to 0 with single supply

Does splitting a potentially monolithic application into several smaller ones help prevent bugs?

PlotLabels with equations not expressions

The use of "touch" and "touch on" in context

Rejected in 4th interview round citing insufficient years of experience

Instead of Universal Basic Income, why not Universal Basic NEEDS?

Calculus II Professor will not accept my correct integral evaluation that uses a different method, should I bring this up further?

Why are there 40 737 Max planes in flight when they have been grounded as not airworthy?

Professor being mistaken for a grad student

2D counterpart of std::array in C++17

What is this large pipe coming out of my roof?

Be in awe of my brilliance!

Life insurance that covers only simultaneous/dual deaths

Sword in the Stone story where the sword was held in place by electromagnets

Does the statement `int val = (++i > ++j) ? ++i : ++j;` invoke undefined behavior?

How could a female member of a species produce eggs unto death?

When do we add an hyphen (-) to a complex adjective word?



Unable to modify Excel from ASP.NET CORE



2019 Community Moderator ElectionHow to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How do I properly clean up Excel interop objects?Collection was modified; enumeration operation may not executeGet int value from enum in C#Error - Unable to access the IIS metabaseASP.NET Core MVC (former MVC 6) Razor errors not getting caught by exception filterHow to dispose of Serilog 2.0 correctly in ASP.NET Core application?How to reference an ASP.NET Core project from a Full .Net framework Test project?System.IdentityModel.Metadata and X509SecurityToken not available in ASP.NET CoreASP.Net Core application can't find Microsoft.ApplicationBlocks.Data assembly










0















I have ASP.Net core project and class library associated. In class library I have my code to update Excel file. It works fine when used in unit test or called from native console app. But it neither throws exception nor modify/update excel file when called from web app.



public bool SaveOrder(Order order)

excelApp = new Excel.Application();
excelBook = excelApp.Workbooks.Open(_dbPath);
orderMenuSheet = (Excel.Worksheet)excelBook.Worksheets.get_Item(2);
try

foreach (var menu in order.OrderItems)

var rowNum = menu.MenuNumber + 2;
orderMenuSheet.Cells[rowNum, 3] = menu.Menu;
orderMenuSheet.Cells[rowNum, 7] = menu.Rating;
orderMenuSheet.Cells[rowNum, 8] = menu.Review;

excelBook.Save();

catch (Exception)

return false;

finally

DisposeExcelObject(); //dispose excel objects

return true;










share|improve this question
























  • @ESG,as mentioned in question, it doesn't give exception

    – Sria Pathre
    Mar 6 at 19:11






  • 2





    Sounds like you are using com. Have you considered to use OpenXml SDK or will you install excel on a web server ? BTW: joelleach.net/2018/06/06/com-interop-with-net-core-2-0

    – tschmit007
    Mar 6 at 19:33







  • 1





    1. If you're using the Microsoft.Office.Interop.Excel/, I could reproduce the same issue as yours . When targeting .netcoreapp2.2, most of operations fail silently except that getting the sheet name succeeds. But it works fine if I target .net472. 2. Are you targeting .NET Framework ? Note this library is not compatible with .NET Core yet.

    – itminus
    Mar 7 at 8:58












  • It works fine with .net framework. I do agree that something is going wrong with .net Core. Even when I save file as new file, new file is created but doesn't contain the changes I made. It just creates copy of existing file.

    – Sria Pathre
    Mar 7 at 14:25






  • 1





    @tschmit007 using openXML worked for me. Thanks for suggestion.

    – Sria Pathre
    Mar 7 at 17:46















0















I have ASP.Net core project and class library associated. In class library I have my code to update Excel file. It works fine when used in unit test or called from native console app. But it neither throws exception nor modify/update excel file when called from web app.



public bool SaveOrder(Order order)

excelApp = new Excel.Application();
excelBook = excelApp.Workbooks.Open(_dbPath);
orderMenuSheet = (Excel.Worksheet)excelBook.Worksheets.get_Item(2);
try

foreach (var menu in order.OrderItems)

var rowNum = menu.MenuNumber + 2;
orderMenuSheet.Cells[rowNum, 3] = menu.Menu;
orderMenuSheet.Cells[rowNum, 7] = menu.Rating;
orderMenuSheet.Cells[rowNum, 8] = menu.Review;

excelBook.Save();

catch (Exception)

return false;

finally

DisposeExcelObject(); //dispose excel objects

return true;










share|improve this question
























  • @ESG,as mentioned in question, it doesn't give exception

    – Sria Pathre
    Mar 6 at 19:11






  • 2





    Sounds like you are using com. Have you considered to use OpenXml SDK or will you install excel on a web server ? BTW: joelleach.net/2018/06/06/com-interop-with-net-core-2-0

    – tschmit007
    Mar 6 at 19:33







  • 1





    1. If you're using the Microsoft.Office.Interop.Excel/, I could reproduce the same issue as yours . When targeting .netcoreapp2.2, most of operations fail silently except that getting the sheet name succeeds. But it works fine if I target .net472. 2. Are you targeting .NET Framework ? Note this library is not compatible with .NET Core yet.

    – itminus
    Mar 7 at 8:58












  • It works fine with .net framework. I do agree that something is going wrong with .net Core. Even when I save file as new file, new file is created but doesn't contain the changes I made. It just creates copy of existing file.

    – Sria Pathre
    Mar 7 at 14:25






  • 1





    @tschmit007 using openXML worked for me. Thanks for suggestion.

    – Sria Pathre
    Mar 7 at 17:46













0












0








0








I have ASP.Net core project and class library associated. In class library I have my code to update Excel file. It works fine when used in unit test or called from native console app. But it neither throws exception nor modify/update excel file when called from web app.



public bool SaveOrder(Order order)

excelApp = new Excel.Application();
excelBook = excelApp.Workbooks.Open(_dbPath);
orderMenuSheet = (Excel.Worksheet)excelBook.Worksheets.get_Item(2);
try

foreach (var menu in order.OrderItems)

var rowNum = menu.MenuNumber + 2;
orderMenuSheet.Cells[rowNum, 3] = menu.Menu;
orderMenuSheet.Cells[rowNum, 7] = menu.Rating;
orderMenuSheet.Cells[rowNum, 8] = menu.Review;

excelBook.Save();

catch (Exception)

return false;

finally

DisposeExcelObject(); //dispose excel objects

return true;










share|improve this question
















I have ASP.Net core project and class library associated. In class library I have my code to update Excel file. It works fine when used in unit test or called from native console app. But it neither throws exception nor modify/update excel file when called from web app.



public bool SaveOrder(Order order)

excelApp = new Excel.Application();
excelBook = excelApp.Workbooks.Open(_dbPath);
orderMenuSheet = (Excel.Worksheet)excelBook.Worksheets.get_Item(2);
try

foreach (var menu in order.OrderItems)

var rowNum = menu.MenuNumber + 2;
orderMenuSheet.Cells[rowNum, 3] = menu.Menu;
orderMenuSheet.Cells[rowNum, 7] = menu.Rating;
orderMenuSheet.Cells[rowNum, 8] = menu.Review;

excelBook.Save();

catch (Exception)

return false;

finally

DisposeExcelObject(); //dispose excel objects

return true;







c# excel asp.net-core






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 18:00









mason

23.8k74683




23.8k74683










asked Mar 6 at 19:06









Sria PathreSria Pathre

1447




1447












  • @ESG,as mentioned in question, it doesn't give exception

    – Sria Pathre
    Mar 6 at 19:11






  • 2





    Sounds like you are using com. Have you considered to use OpenXml SDK or will you install excel on a web server ? BTW: joelleach.net/2018/06/06/com-interop-with-net-core-2-0

    – tschmit007
    Mar 6 at 19:33







  • 1





    1. If you're using the Microsoft.Office.Interop.Excel/, I could reproduce the same issue as yours . When targeting .netcoreapp2.2, most of operations fail silently except that getting the sheet name succeeds. But it works fine if I target .net472. 2. Are you targeting .NET Framework ? Note this library is not compatible with .NET Core yet.

    – itminus
    Mar 7 at 8:58












  • It works fine with .net framework. I do agree that something is going wrong with .net Core. Even when I save file as new file, new file is created but doesn't contain the changes I made. It just creates copy of existing file.

    – Sria Pathre
    Mar 7 at 14:25






  • 1





    @tschmit007 using openXML worked for me. Thanks for suggestion.

    – Sria Pathre
    Mar 7 at 17:46

















  • @ESG,as mentioned in question, it doesn't give exception

    – Sria Pathre
    Mar 6 at 19:11






  • 2





    Sounds like you are using com. Have you considered to use OpenXml SDK or will you install excel on a web server ? BTW: joelleach.net/2018/06/06/com-interop-with-net-core-2-0

    – tschmit007
    Mar 6 at 19:33







  • 1





    1. If you're using the Microsoft.Office.Interop.Excel/, I could reproduce the same issue as yours . When targeting .netcoreapp2.2, most of operations fail silently except that getting the sheet name succeeds. But it works fine if I target .net472. 2. Are you targeting .NET Framework ? Note this library is not compatible with .NET Core yet.

    – itminus
    Mar 7 at 8:58












  • It works fine with .net framework. I do agree that something is going wrong with .net Core. Even when I save file as new file, new file is created but doesn't contain the changes I made. It just creates copy of existing file.

    – Sria Pathre
    Mar 7 at 14:25






  • 1





    @tschmit007 using openXML worked for me. Thanks for suggestion.

    – Sria Pathre
    Mar 7 at 17:46
















@ESG,as mentioned in question, it doesn't give exception

– Sria Pathre
Mar 6 at 19:11





@ESG,as mentioned in question, it doesn't give exception

– Sria Pathre
Mar 6 at 19:11




2




2





Sounds like you are using com. Have you considered to use OpenXml SDK or will you install excel on a web server ? BTW: joelleach.net/2018/06/06/com-interop-with-net-core-2-0

– tschmit007
Mar 6 at 19:33






Sounds like you are using com. Have you considered to use OpenXml SDK or will you install excel on a web server ? BTW: joelleach.net/2018/06/06/com-interop-with-net-core-2-0

– tschmit007
Mar 6 at 19:33





1




1





1. If you're using the Microsoft.Office.Interop.Excel/, I could reproduce the same issue as yours . When targeting .netcoreapp2.2, most of operations fail silently except that getting the sheet name succeeds. But it works fine if I target .net472. 2. Are you targeting .NET Framework ? Note this library is not compatible with .NET Core yet.

– itminus
Mar 7 at 8:58






1. If you're using the Microsoft.Office.Interop.Excel/, I could reproduce the same issue as yours . When targeting .netcoreapp2.2, most of operations fail silently except that getting the sheet name succeeds. But it works fine if I target .net472. 2. Are you targeting .NET Framework ? Note this library is not compatible with .NET Core yet.

– itminus
Mar 7 at 8:58














It works fine with .net framework. I do agree that something is going wrong with .net Core. Even when I save file as new file, new file is created but doesn't contain the changes I made. It just creates copy of existing file.

– Sria Pathre
Mar 7 at 14:25





It works fine with .net framework. I do agree that something is going wrong with .net Core. Even when I save file as new file, new file is created but doesn't contain the changes I made. It just creates copy of existing file.

– Sria Pathre
Mar 7 at 14:25




1




1





@tschmit007 using openXML worked for me. Thanks for suggestion.

– Sria Pathre
Mar 7 at 17:46





@tschmit007 using openXML worked for me. Thanks for suggestion.

– Sria Pathre
Mar 7 at 17:46












1 Answer
1






active

oldest

votes


















0














i change some code and its works for me.i Hope it will help



 System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

// Creating Excel Application
Microsoft.Office.Interop.Excel._Application excelApp = new Microsoft.Office.Interop.Excel.Application();
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;

var fileName = Path.Combine(_he.WebRootPath + "\ClientFile", "test.xlsx");
var excelBook = excelApp.Workbooks.Open(fileName);
var orderMenuSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelBook.Sheets["QUESTIONNAIRE PACK"];
foreach (var menu in order.OrderItems)

var rowNum = menu.MenuNumber + 2;
orderMenuSheet.Cells[rowNum, 3] = menu.Menu;
orderMenuSheet.Cells[rowNum, 7] = menu.Rating;
orderMenuSheet.Cells[rowNum, 8] = menu.Review;

excelBook.Save();





share|improve this answer

























  • Nope. It doesn't work.

    – Sria Pathre
    Mar 7 at 15:20











  • @SriaPathre Sorry, misunderstood about this ticket. I am try getting data instead of edit. I can now edit excel .i just update my code and it works for me

    – jalil
    Mar 7 at 16:11












  • As discussed above, Microsoft.Office.Interop.Excel doesn't work with ASP.NET core. It silently fails without exception. So changed my code to OpenXML and works fine now. Thanks for your efforts @jalil.

    – Sria Pathre
    Mar 11 at 13:33










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55030470%2funable-to-modify-excel-from-asp-net-core%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














i change some code and its works for me.i Hope it will help



 System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

// Creating Excel Application
Microsoft.Office.Interop.Excel._Application excelApp = new Microsoft.Office.Interop.Excel.Application();
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;

var fileName = Path.Combine(_he.WebRootPath + "\ClientFile", "test.xlsx");
var excelBook = excelApp.Workbooks.Open(fileName);
var orderMenuSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelBook.Sheets["QUESTIONNAIRE PACK"];
foreach (var menu in order.OrderItems)

var rowNum = menu.MenuNumber + 2;
orderMenuSheet.Cells[rowNum, 3] = menu.Menu;
orderMenuSheet.Cells[rowNum, 7] = menu.Rating;
orderMenuSheet.Cells[rowNum, 8] = menu.Review;

excelBook.Save();





share|improve this answer

























  • Nope. It doesn't work.

    – Sria Pathre
    Mar 7 at 15:20











  • @SriaPathre Sorry, misunderstood about this ticket. I am try getting data instead of edit. I can now edit excel .i just update my code and it works for me

    – jalil
    Mar 7 at 16:11












  • As discussed above, Microsoft.Office.Interop.Excel doesn't work with ASP.NET core. It silently fails without exception. So changed my code to OpenXML and works fine now. Thanks for your efforts @jalil.

    – Sria Pathre
    Mar 11 at 13:33















0














i change some code and its works for me.i Hope it will help



 System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

// Creating Excel Application
Microsoft.Office.Interop.Excel._Application excelApp = new Microsoft.Office.Interop.Excel.Application();
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;

var fileName = Path.Combine(_he.WebRootPath + "\ClientFile", "test.xlsx");
var excelBook = excelApp.Workbooks.Open(fileName);
var orderMenuSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelBook.Sheets["QUESTIONNAIRE PACK"];
foreach (var menu in order.OrderItems)

var rowNum = menu.MenuNumber + 2;
orderMenuSheet.Cells[rowNum, 3] = menu.Menu;
orderMenuSheet.Cells[rowNum, 7] = menu.Rating;
orderMenuSheet.Cells[rowNum, 8] = menu.Review;

excelBook.Save();





share|improve this answer

























  • Nope. It doesn't work.

    – Sria Pathre
    Mar 7 at 15:20











  • @SriaPathre Sorry, misunderstood about this ticket. I am try getting data instead of edit. I can now edit excel .i just update my code and it works for me

    – jalil
    Mar 7 at 16:11












  • As discussed above, Microsoft.Office.Interop.Excel doesn't work with ASP.NET core. It silently fails without exception. So changed my code to OpenXML and works fine now. Thanks for your efforts @jalil.

    – Sria Pathre
    Mar 11 at 13:33













0












0








0







i change some code and its works for me.i Hope it will help



 System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

// Creating Excel Application
Microsoft.Office.Interop.Excel._Application excelApp = new Microsoft.Office.Interop.Excel.Application();
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;

var fileName = Path.Combine(_he.WebRootPath + "\ClientFile", "test.xlsx");
var excelBook = excelApp.Workbooks.Open(fileName);
var orderMenuSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelBook.Sheets["QUESTIONNAIRE PACK"];
foreach (var menu in order.OrderItems)

var rowNum = menu.MenuNumber + 2;
orderMenuSheet.Cells[rowNum, 3] = menu.Menu;
orderMenuSheet.Cells[rowNum, 7] = menu.Rating;
orderMenuSheet.Cells[rowNum, 8] = menu.Review;

excelBook.Save();





share|improve this answer















i change some code and its works for me.i Hope it will help



 System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

// Creating Excel Application
Microsoft.Office.Interop.Excel._Application excelApp = new Microsoft.Office.Interop.Excel.Application();
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;

var fileName = Path.Combine(_he.WebRootPath + "\ClientFile", "test.xlsx");
var excelBook = excelApp.Workbooks.Open(fileName);
var orderMenuSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelBook.Sheets["QUESTIONNAIRE PACK"];
foreach (var menu in order.OrderItems)

var rowNum = menu.MenuNumber + 2;
orderMenuSheet.Cells[rowNum, 3] = menu.Menu;
orderMenuSheet.Cells[rowNum, 7] = menu.Rating;
orderMenuSheet.Cells[rowNum, 8] = menu.Review;

excelBook.Save();






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 7 at 16:09

























answered Mar 6 at 21:13









jaliljalil

576




576












  • Nope. It doesn't work.

    – Sria Pathre
    Mar 7 at 15:20











  • @SriaPathre Sorry, misunderstood about this ticket. I am try getting data instead of edit. I can now edit excel .i just update my code and it works for me

    – jalil
    Mar 7 at 16:11












  • As discussed above, Microsoft.Office.Interop.Excel doesn't work with ASP.NET core. It silently fails without exception. So changed my code to OpenXML and works fine now. Thanks for your efforts @jalil.

    – Sria Pathre
    Mar 11 at 13:33

















  • Nope. It doesn't work.

    – Sria Pathre
    Mar 7 at 15:20











  • @SriaPathre Sorry, misunderstood about this ticket. I am try getting data instead of edit. I can now edit excel .i just update my code and it works for me

    – jalil
    Mar 7 at 16:11












  • As discussed above, Microsoft.Office.Interop.Excel doesn't work with ASP.NET core. It silently fails without exception. So changed my code to OpenXML and works fine now. Thanks for your efforts @jalil.

    – Sria Pathre
    Mar 11 at 13:33
















Nope. It doesn't work.

– Sria Pathre
Mar 7 at 15:20





Nope. It doesn't work.

– Sria Pathre
Mar 7 at 15:20













@SriaPathre Sorry, misunderstood about this ticket. I am try getting data instead of edit. I can now edit excel .i just update my code and it works for me

– jalil
Mar 7 at 16:11






@SriaPathre Sorry, misunderstood about this ticket. I am try getting data instead of edit. I can now edit excel .i just update my code and it works for me

– jalil
Mar 7 at 16:11














As discussed above, Microsoft.Office.Interop.Excel doesn't work with ASP.NET core. It silently fails without exception. So changed my code to OpenXML and works fine now. Thanks for your efforts @jalil.

– Sria Pathre
Mar 11 at 13:33





As discussed above, Microsoft.Office.Interop.Excel doesn't work with ASP.NET core. It silently fails without exception. So changed my code to OpenXML and works fine now. Thanks for your efforts @jalil.

– Sria Pathre
Mar 11 at 13:33



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55030470%2funable-to-modify-excel-from-asp-net-core%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко