title: Modifying a cell with OpenXML in VB.Net
body: <p>I don't know why I'm having such a hard time finding examples for this simple task, but nothing is showing based on my Google-Fu skills.  I'm looking for an example of modifying a cell of an existing spreadsheet using OpenXML and VB.Net.</p>
  
  <p>I want to change the existing value to a new one, no formulas involved.</p>
  
  <p>Here is what I have:</p>
  
  <pre><code>Public Sub Main()
      Dim strSource, strSheetName As String
      Dim dtPeriod As DateTime
  
      strSource = Dts.Variables("sFilePath").Value
  
      'set period to previous month. We only care about the year in this period as the data will be reloaded
      'from the file each month
      dtPeriod = DateAdd(DateInterval.Month, -1, Today)
      Dts.Variables("dtPeriod").Value = dtPeriod
  
      Using mySpreadSheet As SpreadsheetDocument = SpreadsheetDocument.Open(strSource, True)
          Dim WorkbookSheets As Sheets
  
          WorkbookSheets = mySpreadSheet.WorkbookPart.Workbook.GetFirstChild(Of Sheets)()
  
          For Each childSheet As Sheet In WorkbookSheets
              strSheetName = childSheet.Name
              strSheetName = strSheetName.ToLower.Trim
  
              If strSheetName = "sheet1" Then     'process sheet
  
                  SetCellValue("A1", "Last Name")
                  SetCellValue("B1", "First Name")
                  SetCellValue("C1", "RegionID")
                  SetCellValue("D1", "RegionName")
  
                  'rename sheet for loading
                  childSheet.Name = "RegionData"
              End If
          Next
  
          mySpreadSheet.WorkbookPart.Workbook.Save()
          mySpreadSheet.Close()
      End Using
  End Sub
  
  Private Sub SetCellValue(ByVal loc As String, ByVal Val As String)
      Dim cell As Cell = New Cell
  
  
      cell.CellReference = loc
      cell.DataType = CellValues.String
      cell.CellValue = New CellValue(Val)
  
  End Sub
  </code></pre>
  
  <p>I'm sure it's something simple like making sure the cell is referencing the correct sheet, but all the examples I've found are for creating a new sheet.</p>
  
  <p>Thanks</p>