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
Kalyani Shevale
NA
3.2k
711.5k
Existing spreadsheet document file create new cell in c#
Nov 21 2018 1:23 AM
I have open existing spreadsheet document file. then this file inserts some cell in the particular index value.
how to insert the new cell in this open file.
DataTable dataTable =
new
DataTable();
using
(SpreadsheetDocument spreadSheetDocument = SpreadsheetDocument.Open(srcFile,
false
))
{
WorkbookPart workbookPart = spreadSheetDocument.WorkbookPart;
IEnumerable<Sheet> sheets = spreadSheetDocument.WorkbookPart.Workbook.GetFirstChild<Sheets>().Elements<Sheet>();
string
relationshipId = sheets.First().Id.Value;
WorksheetPart worksheetPart = (WorksheetPart)spreadSheetDocument.WorkbookPart.GetPartById(relationshipId);
Worksheet workSheet = worksheetPart.Worksheet;
SheetData sheetData = workSheet.GetFirstChild<SheetData>();
IEnumerable<Row> rows = sheetData.Descendants<Row>();
foreach
(Cell cell
in
rows.ElementAt(0))
{
dataTable.Columns.Add(GetCellValue(spreadSheetDocument, cell));
}
ArrayList list =
new
ArrayList();
foreach
(Row row
in
rows)
{
DataRow dataRow = dataTable.NewRow();
for
(
int
i = 0; i < 1; i++)
{
list.Add(GetCellValue(spreadSheetDocument, row.Descendants<Cell>().ElementAt(i)));
}
}
Row row1 =
new
Row() { RowIndex = 2U, Spans =
new
ListValue<StringValue>() };
Cell cell1 =
new
Cell()
{
CellReference =
"A52"
,
DataType = CellValues.String,
CellValue =
new
CellValue(
"Microsoft"
)
};
Row r =
new
Row();
r.Append(cell1);
sheetData.AppendChild(r);
worksheetPart.Worksheet.Append(sheetData);
worksheetPart.Worksheet.Save();
}
problem in last 5 line how to insert new cell value in this existing file in c#
Reply
Answers (
5
)
Error Installing Nuget Package. (Bot builder 4.1.5 ).
on Server Excel open & write problem occured