TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abdul Hameed
NA
53
1.7k
Writing to excel using Open XML
Mar 7 2019 11:46 PM
I have written a code to write to an excel file in OpenXML. this works for only one time for the second time, I am getting an error while opening the file as "We found a problem with some content in output.xlsx"
public
static
void
WriteToExcel(
string
fileName,
string
SKU_Address,
string
SKU_Value,
string
ItemName_Address,
string
Item_Name_Value)
{
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(fileName,
true
);
// Add a WorkbookPart to the document.
WorkbookPart workbookpart = spreadsheetDocument.WorkbookPart;
// Add a WorksheetPart to the WorkbookPart.
WorksheetPart worksheetPart = workbookpart.WorksheetParts.FirstOrDefault();
Worksheet worksheet = worksheetPart.Worksheet;
SheetData sheetData = worksheetPart.Worksheet.Elements<SheetData>().First();
Row row =
new
Row();
//intialize a cell and add values to the required cell based on address
Cell cell1 =
new
Cell()
{
CellReference = SKU_Address,
DataType = CellValues.String,
CellValue =
new
CellValue(SKU_Value)
};
row.Append(cell1);
//intialize a cell and add values to the required cell based on address
Cell cell2 =
new
Cell()
{
CellReference = ItemName_Address,
DataType = CellValues.String,
CellValue =
new
CellValue(Item_Name_Value)
};
row.Append(cell2);
sheetData.Append(row);
worksheetPart.Worksheet.Save();
// Close the document.
spreadsheetDocument.Close();
}
I guess I am missing something somewhere else. please help.
Reply
Answers (
2
)
Reading Storing CSV Data into an Array
Redirect to one domain to another domain.