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
Soumyadeeep Raha
NA
18
1.1k
Excel Open error: “found unreadable content in APPL_1.xlsx”
Dec 24 2018 5:17 AM
I am getting error 'Excel found unreadable content in APPL_1.xlsx.' What is wrong in my code?.
Record contain around 2 lacks data. I am trying to fetch it from datatable to excel.
I am using OpenXMLSpreedsheetDocument to fetch data from datatable to excel.
Any suggestions is much appreciated..!!
public
void
ExportDataTable_SpreadsheetDocument(DataTable dt,
string
FilePath)
{
try
{
FileInfo FileLoc =
new
FileInfo(FilePath);
if
(FileLoc.Exists)
{
FileLoc.Delete();
FileLoc =
new
FileInfo(FilePath);
}
SpreadsheetDocument spreadSheet = SpreadsheetDocument.
Create(FilePath, SpreadsheetDocumentType.Workbook);
// Add a WorkbookPart to the document.
WorkbookPart workbookpart = spreadSheet.AddWorkbookPart();
workbookpart.Workbook =
new
Workbook();
// Add a WorksheetPart to the WorkbookPart.
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
var sheetData =
new
SheetData();
worksheetPart.Worksheet =
new
Worksheet(sheetData);
var bold1 =
new
Bold();
CellFormat cf =
new
CellFormat();
// Add Sheets to the Workbook.
Sheets sheets;
sheets = spreadSheet.WorkbookPart.Workbook.
AppendChild<Sheets>(
new
Sheets());
// Append a new worksheet and associate it with the workbook.
var sheet =
new
Sheet()
{
Id = spreadSheet.WorkbookPart.
GetIdOfPart(worksheetPart),
SheetId = 0,
Name =
"Sheet"
+ 0
};
sheets.Append(sheet);
//Add Header Row.
var headerRow =
new
Row();
foreach
(DataColumn column
in
dt.Columns)
{
var cell =
new
Cell
{
DataType = CellValues.String,
CellValue =
new
CellValue(column.ColumnName)
};
headerRow.AppendChild(cell);
}
sheetData.AppendChild(headerRow);
foreach
(DataRow row
in
dt.Rows)
{
var newRow =
new
Row();
foreach
(DataColumn col
in
dt.Columns)
{
Cell c =
new
Cell();
c.DataType =
new
EnumValue<CellValues>(CellValues.String);
c.CellValue =
new
CellValue(row[col].ToString());
newRow.Append(c);
}
sheetData.AppendChild(newRow);
}
workbookpart.Workbook.Save();
ProcessStartInfo startInfo =
new
ProcessStartInfo(FilePath);
Process.Start(startInfo);
}
catch
(Exception ex)
{
}
}
Reply
Answers (
0
)
Element “webBrowser”. How to wait for the page to load?
How to generate the output as pdf/Excel n MVC with angularJs