How to – Update Cell value in Excel Spreadsheet using C# (Open XML and EPPlus library)


Sharing a sample code that updates a particular cell’s value in Excel Spreadsheet.

Here we are updating cell B4

First using Open XML SDK

</p>
<p>public static void UpdateExcelUsingOpenXMLSDK(string fileName)<br />
{<br />
// Open the document for editing.<br />
using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Open(fileName, true))<br />
{<br />
// Access the main Workbook part, which contains all references.<br />
WorkbookPart workbookPart = spreadSheet.WorkbookPart;<br />
// get sheet by name<br />
Sheet sheet = workbookPart.Workbook.Descendants&lt;Sheet&gt;().Where(s =&gt; s.Name == "Sheet1").FirstOrDefault();</p>
<p>// get worksheetpart by sheet id<br />
WorksheetPart worksheetPart = workbookPart.GetPartById(sheet.Id.Value) as WorksheetPart;</p>
<p>// The SheetData object will contain all the data.<br />
SheetData sheetData = worksheetPart.Worksheet.GetFirstChild();</p>
<p>Cell cell = GetCell(worksheetPart.Worksheet, "B", 4);</p>
<p>cell.CellValue = new CellValue("10");<br />
cell.DataType = new EnumValue&lt;CellValues&gt;(CellValues.Number);</p>
<p>// Save the worksheet.<br />
worksheetPart.Worksheet.Save();</p>
<p>// for recacluation of formula<br />
spreadSheet.WorkbookPart.Workbook.CalculationProperties.ForceFullCalculation = true;<br />
spreadSheet.WorkbookPart.Workbook.CalculationProperties.FullCalculationOnLoad = true;</p>
<p>}<br />
}</p>
<p>private static Cell GetCell(Worksheet worksheet,<br />
string columnName, uint rowIndex)<br />
{<br />
Row row = GetRow(worksheet, rowIndex);</p>
<p>if (row == null) return null;</p>
<p>var FirstRow = row.Elements&lt;Cell&gt;().Where(c =&gt; string.Compare<br />
(c.CellReference.Value, columnName +<br />
rowIndex, true) == 0).FirstOrDefault();</p>
<p>if (FirstRow == null) return null;</p>
<p>return FirstRow;<br />
}</p>
<p>private static Row GetRow(Worksheet worksheet , uint rowIndex)<br />
{<br />
Row row = worksheet.GetFirstChild&lt;SheetData&gt;().<br />
Elements&lt;Row&gt;().FirstOrDefault(r =&gt; r.RowIndex == rowIndex);<br />
if (row == null)<br />
{<br />
throw new ArgumentException(String.Format("No row with index {0} found in spreadsheet", rowIndex));<br />
}<br />
return row;<br />
}</p>
<p>

Now the same code using EPPlus

https://www.nuget.org/packages/EPPlus/

</p>
<p>public void UpdateExcelUsingEPPlus(string fileName)<br />
{<br />
FileInfo fileInfo = new FileInfo(fileName);<br />
ExcelPackage p = new ExcelPackage(fileInfo);<br />
ExcelWorksheet myWorksheet = p.Workbook.Worksheets["Sheet1"];<br />
myWorksheet.Cells[4, 2].Value = 10;<br />
p.Save();</p>
<p>}</p>
<p>

Hope it helps..

Advertisements

Setting Regarding of a record in Automatic Record Creation and Update Rules in Dynamics 365


Hi,

While implementing a scenario i.e. automatic case creation on phone call create using Automatic Record Creation and Updating Rules, we found that whenever we were setting the Regarding Object in the Phone Call activity, the case record was not getting created.

Create Case Rule Item –

Creating a Phone Call record using Case as Regarding object.

Workflow ran but the case record was not created.

Then we created phone call activity record without setting the regarding object. This time workflow ran and created the case record.

Basically, the workflow creates the case record and updates the Regarding Object in the Phone call record with this newly created case record.

However, if we check the Official documentation

https://www.microsoft.com/en-us/dynamics/crm-customer-center/set-up-rules-to-automatically-create-or-update-records-in-dynamics-365-customer-service.aspx#bkmk_RuleAndQueues

we have this mentioned

However, in our case we created a phone call record with case as regarding object and had case as the entity selected in the Create Record step, in this case also the Action were not executed.

Hope it helps..

Unknown Error or Resource not found for the segment ‘msdyn_FpsAction’ in Schedule Board in Field Service in Dynamics 365.


Hi,

Recently we configured the portal trial instance and installed Partner Field Service portal in it .

However, while trying to access Field Service à Schedule Board, we were getting the below errors

Eventually it turned out that the issue was caused because of the certain processes being in draft state.

The post which helped in fixing this issue

https://glinks.co.uk/2017/01/06/field-services-schedule-board-unknown-error/

Hope it helps..

Liquid Part 3 – Displaying a List of Dynamics 365 Records


Liquid Markup and Entity Lists in Portal in Dynamics 365

Nick Doelman's avatarThe ReadyXRM Blog by Nick Doelman

Just a heads up that I will be presenting a webinar for the XRM Virtual User Group on March 28, 2017 called “Portal Developer Primer”.  This session is focused for the Dynamics 365/CRM developer who needs to start getting ramped up on Portal development.  It is an evolution from my session at ExtremeCRM in Newport Beach.  Click here to Check it out!

Liquid Part 3

In Liquid Part 2 I demostrated how you can surface data from Dynamics 365 record on the portal.  The great thing about using Liquid is that you can format and modify the layout any way you like.

In today’s post I will be show how to display a bunch of Dynamics 365 records using a custom Liquid Web Template.

If you have done any Dynamics 365 Portal configuration, you know you can surface Dynamics 365 records by using Entity Lists.  Entity Lists surface Dynamics 365…

View original post 593 more words

More Liquid Markup in Dynamics 365 Retrieving Entity Record Data (Part 2)


Liquid Markup to show Entity Record in Portal in Dynamics 365

Nick Doelman's avatarThe ReadyXRM Blog by Nick Doelman

Before we dive into today’s tutorial, today Adoxio (the consulting arm of the old Adxstudio) released Adoxio Connect Framework to allow seamless integration to other platforms.  Something I will be definitely checking out.

Retrieving Dynamics 365 Data with Liquid

In Part 1 we looked at a very basic Web Template using Liquid.  One of the great things about the Liquid Markup code is that it can be incorporated into other areas like Web Page copy and Content Snippets.

Microsoft’s implementation of Liquid can also be used to show data from Dynamics 365 (Customer Engagement).

In my example, I am going to use Liquid to retrieve an Invoice and show the Invoice Name, the Invoice Status and the Invoice Amount and display that on a Web page.

In order to be able to show some data, we need to be able to know what record we want to pull from Dyn365…

View original post 432 more words

List of all blog posts on CRM and Azure Integration


 

Advertisements

Nishant Rana's Weblog

Everything related to Microsoft .NET Technology

Skip to content ↓