I have got column index for an excel column in a spreadsheet and need to delete the entire column using this column index. I am confined to use Open XML SDK 2.0.
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
namespace openXMLDemo
{
public class Program
{
public static void Main(string[] args)
{
string fileFullPath = @"path to the excel file here";
string sheetName = "excelsheet name here";
using (SpreadsheetDocument document = SpreadsheetDocument.Open(fileFullPath, true))
{
Sheet sheet = document.WorkbookPart.Workbook.GetFirstChild<Sheets>().Elements<Sheet>().Where(s => s.Name == sheetName).FirstOrDefault();
if (sheet != null)
{
WorksheetPart worksheetPart = (WorksheetPart)document.WorkbookPart.GetPartById(sheet.Id.Value);
// This is where I am struggling....
// finding the reference to entire column with the use of column index
Column columnToDelete = sheet.GetFirstChild<SheetData>().Elements<Column>()
}
}
}
}
}
Column
elements only contain layout / styling information for a [range of] columns in an spreadsheet, the actual data is stored inCell
elements, contained in individualRow
elements within theSheetData
element) – bassfader