15,908,455 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by EricERankin (Top 7 by date)
EricERankin
15-Apr-20 1:10am
View
Looking at your
buttonSplit_Click
it seems like you want to save each individual page into a separate file, is that correct?
In that case, take a look at this example of how to
split PDF file in C#
, it generates a PDF file for each PDF page.
EricERankin
15-Apr-20 0:49am
View
Here is the simplest was I know how to
export DataGridView to an Excel file in VB.NET
:
-------
Dim saveFileDialog = New SaveFileDialog()
If (saveFileDialog.ShowDialog() = DialogResult.OK) Then
Dim workbook = New ExcelFile()
Dim worksheet = workbook.Worksheets.Add("Sheet1")
' Export data from DataGridView to ExcelFile.
DataGridViewConverter.ImportFromDataGridView(worksheet, Me.dataGridView1, New ImportFromDataGridViewOptions() With {.ColumnHeaders = True})
workbook.Save(saveFileDialog.FileName)
End If
-------
This doesn't use Office Interop, instead it uses an
Excel library for VB.NET
.
EricERankin
15-Apr-20 0:41am
View
Excel Interop is not known for its efficiency, it is a wrapper for GUI application so the performances can be questionable at times, especially in case of large files.
If you can change your approach, then here is an alternative that uses GemBox.Spreadsheet to retrieve faster all the cells formatted values:
----
var workbook = ExcelFile.Load("input.xlsx");
var worksheet = workbook.Worksheets.ActiveWorksheet;
int rowCount = worksheet.Rows.Count;
int columnCount = worksheet.CalculateMaxUsedColumns();
string[,] values = new string[rowCount, columnCount];
for (int r = 0; r < rowCount; r++)
for (int j = 0; j < columnCount; j++)
values[r, j] = worksheet.Cells[r, j].GetFormattedValue();
----
Also, here is another example for
reading Excel files from C#
in a
clean and efficient
way.
EricERankin
26-Mar-20 13:48pm
View
Your question is a bit ambiguous, nevertheless, here is how you can
export datatable into excel file
:
--------
string directory = @"C:\NOTES";
if (!Directory.Exists(directory))
Directory.CreateDirectory(directory);
var dataTable = ExcelTable();
var workbook = new ExcelFile();
var worksheet = workbook.Worksheets.Add("Sheet1");
worksheet.InsertDataTable(dataTable, new InsertDataTableOptions() { ColumnHeaders = true });
var table = worksheet.Tables.Add("InformationTable", worksheet.GetUsedCellRange(true), true);
table.BuiltInStyle = BuiltInTableStyleName.TableStyleMedium2;
workbook.Save(Path.Combine(directory, "InformationTable.xlsx"));
--------
If you need to
print an excel file from c#
then just add this:
--------
workbook.Print("Your printer's name or use 'null' for default printer.");
--------
EricERankin
26-Mar-20 13:32pm
View
Let's say you have those values in an Excel file under columns A and B, here is how you would update your XML file with that data:
-----------
var workbook = ExcelFile.Load("input.xlsx");
var worksheet = workbook.Worksheets[0];
var xml = new XmlDocument();
xml.Load("box.xml");
var nodes = xml.DocumentElement.ChildNodes.Cast<XmlNode>().ToArray();
for (int index = 0; index < 4; index++)
{
var row = worksheet.Rows[index];
var node = nodes[index];
node.Attributes["X"].Value = row.Cells["A"].Value.ToString();
node.Attributes["Y"].Value = row.Cells["B"].Value.ToString();
}
xml.Save("box-updated.xml");
-----------
The code is
processing Excel using this C# library
.
Also, you can as a reference this
full C# example for reading Excel files
.
I hope this helps.
EricERankin
25-Mar-20 13:43pm
View
You don't have to create another worksheet for this.
Instead, you can specify print area and Excel will export just that area.
For example, try something like this:
xlSH.PageSetup.PrintArea = "B1:D50"
EricERankin
25-Mar-20 13:27pm
View
You can refer to this
Print PDF files in C# and VB.NET
.
Note, you can find examples for Console, Windows Forms and WPF applications, they all use the same
C# and VB.NET library for PDF
.
Show More