Modify an openxml Excel file

Hello,

I've a problem to modify a sheet in my Excel document. All the files present in the package are removed when I execute this code :

Package pkgOutputDoc = Package.Open(fileName, FileMode.Create, FileAccess.ReadWrite);
Uri uri = new Uri(string.Format("/xl/worksheets/sheet{0}.xml", sheetNumber), UriKind.Relative);
PackagePart partSheetXml = pkgOutputDoc.CreatePart(uri, "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml");
StreamWriter streamStartPart = new StreamWriter(partSheetXml.GetStream(FileMode.Create, FileAccess.Write));
xmlStartPart.Save(streamStartPart);
streamStartPart.Close();
pkgOutputDoc.Flush();
pkgOutputDoc.CreateRelationship(uri, TargetMode.Internal,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
"rId1");
pkgOutputDoc.Flush();
pkgOutputDoc.Close();

I don't want to create a new openxml Excel file. I just want to modify a sheet. Could you tell me what is wrong in the above code ?

Thanks for any help,

mathmax

[1200 byte] By [mathmax] at [2008-2-5]
# 1
I think you should not use FileMode.Create.
Package pkgOutputDoc = Package.Open(fileName, FileMode.Create, FileAccess.ReadWrite);
should be
Package pkgOutputDoc = Package.Open(fileName, FileMode.Open, FileAccess.ReadWrite);
ShiguangDong at 2007-9-28 > top of Msdn Tech,Office Live Development,Microsoft SDK for Open XML Formats...