You can use a library called ExcelLibrary. It's a free, open source library posted on Google Code:
ExcelLibrary
This looks to be a port of the PHP ExcelWriter that you mentioned above. It will not write to the new .xlsx format yet, but they are working on adding that functionality in.
It's very simple, small and easy to use. Plus it has a DataSetHelper that lets you use DataSets and DataTables to easily work with Excel data.
ExcelLibrary seems to still only work for the older Excel format (.xls files), but may be adding support in the future for newer 2007/2010 formats.
You can also use EPPlus, which works only for Excel 2007/2010 format files (.xlsx files). There's also NPOI which works with both.
There are a few known bugs with each library as noted in the comments. In all, EPPlus seems to be the best choice as time goes on. It seems to be more actively updated and documented as well.
Also, as noted by @АртёмЦарионов below, EPPlus has support for Pivot Tables and ExcelLibrary may have some support (Pivot table issue in ExcelLibrary)
Here are a couple links for quick reference:
ExcelLibrary - GNU Lesser GPL
EPPlus - GNU (LGPL) - No longer maintained
EPPlus 5 - Polyform Noncommercial - Starting May 2020
NPOI - Apache License
Here some example code for ExcelLibrary:
Here is an example taking data from a database and creating a workbook from it. Note that the ExcelLibrary code is the single line at the bottom:
//Create the data set and table
DataSet ds = new DataSet("New_DataSet");
DataTable dt = new DataTable("New_DataTable");
//Set the locale for each
ds.Locale = System.Threading.Thread.CurrentThread.CurrentCulture;
dt.Locale = System.Threading.Thread.CurrentThread.CurrentCulture;
//Open a DB connection (in this example with OleDB)
OleDbConnection con = new OleDbConnection(dbConnectionString);
con.Open();
//Create a query and fill the data table with the data from the DB
string sql = "SELECT Whatever FROM MyDBTable;";
OleDbCommand cmd = new OleDbCommand(sql, con);
OleDbDataAdapter adptr = new OleDbDataAdapter();
adptr.SelectCommand = cmd;
adptr.Fill(dt);
con.Close();
//Add the table to the data set
ds.Tables.Add(dt);
//Here's the easy part. Create the Excel worksheet from the data set
ExcelLibrary.DataSetHelper.CreateWorkbook("MyExcelFile.xls", ds);
Creating the Excel file is as easy as that. You can also manually create Excel files, but the above functionality is what really impressed me.
Okay, something like the following will fix the issue:
Public Shared Function GetDpiAdjustedMargins(ByVal WindowHandle As IntPtr, ByVal Left As Integer, ByVal Right As Integer, ByVal Top As Integer, ByVal Bottom As Integer) As Margins
'
Dim Graphics As System.Drawing.Graphics = System.Drawing.Graphics.FromHwnd(WindowHandle)
Dim DesktopDPIx As Single = Graphics.DpiX
Dim DesktopDPIy As Single = Graphics.DpiY
Dim Margins As Margins = New Margins
Margins.Left = Left * (DesktopDPIx / 96)
Margins.Right = Right * (DesktopDPIx / 96)
Margins.Top = Top * (DesktopDPIx / 96)
Margins.Bottom = Bottom * (DesktopDPIx / 96)
Return Margins
'
End Function
Source: Pro WPF in C# 2008 By Matthew MacDonald
Best Answer
Nir's answer is correct; when composition is disabled you have to draw that area yourself.
i can show you the code i have in the paint handler of the panel at the top of my form - the panel normally responsible for drawing the 0x00000000 transparent black to make the glass appear:
Psuedo-code:
Sample usage
Bonus Screenshot
Update 7/9/2014
@JakePetroules was right, and i was wrong. The "blue" used for fake glass is not hard-coded into Windows. And it is accessible using
GetThemeColor
.I coded up all the available colors (
TMT_COLOR
) available for a Window class:When using:
Window
WP_CAPTION
and fetch the color code propertyID:
TMT_FILLCOLORHINT
: for when the window has focusTMT_BORDERCOLORHINT
: for when the window does not have focusyou get the two important colors:
The pseudo-code i now use to get the fake glass color:
In reality, since i use Delphi, my actual code is: