Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all 1877 articles
Browse latest View live

New Post: Closing a ClosedXML generated Workbook.

$
0
0
It is also possible that the email sending is not releasing the file.

New Post: Copying range become very slow than copying with Microsoft Interop Service

$
0
0
I can't imagine what you're doing here but it seems you can copy the range then copy the 2 ranges, then 4, then 8, etc.

The copy itself is expensive so there's little to do about it at the moment.

New Post: Adding images to worksheet

$
0
0
I just asked the CodePlex team to migrate this project to GIT. That way you (and everyone else) can submit pull requests much more easily.

Thanks for the help.

New Post: Adding images to worksheet

$
0
0
Fantastic! We'd much prefer to work with git in any case.

New Post: Closing a ClosedXML generated Workbook.

$
0
0
Good morning to both of you,

Apologies for not having replied sooner, but I couldn't get ahold of the code to test it until today.
As roberttanenbaum said, it was the email sending process not releasing the file. I commented the whole block where the mail was being sent and the File.Delete line worked like a charm.

Thanks for both of your replies, and especially to the ClosedXML crew for making such a wonderful piece of code.

Good day!

New Post: Using foreach to deal with Excel rows and skip the 1st row as header

$
0
0
It really helped, but the trick was to use the correct type of parameter in Rows().
Since Rows() doesn't work, I used Rows((Func<IXLTableRow, bool>)null) and works fine.

The code changed to
foreach (var row in table.DataRange.Rows((Func<IXLTableRow, bool>)null)) 
{
  var name = row.Field("Name").GetString();
}
Thank you all!

New Post: Adding images to worksheet

$
0
0
It's on git now. I haven't tested it yet but submit your pull request and we'll see how it goes :)

New Post: Does ClosedXML instantiate a new instance of Excel?

$
0
0
I am writing a C# program that will run on a task scheduler 3 - 4 times a day. It will be installed on a server that is also used as a terminal server w/ folks using Remote Desktop to access it numerous times a day. That being said, I can't just arbitrarily install Excel on it b/c Microsoft requires different licensing if the server is used as a terminal server. When I test my program on the server, it acts like it is running successfully but the spreadsheet never gets created. I have plenty of logging, so I know that it has gotten past the new XLWorkbook() line and has went through a WHILE loop populating the cells (supposedly). I don't need to open the spreadsheet on the server, rather it will just be created and then used as an import file into 3rd party web application. Will it only work if Excel is installed on the server? I don't get any errors telling me that it can't find Excel or anything to point me in the right direction.

New Post: Does ClosedXML instantiate a new instance of Excel?

$
0
0
You do not need Excel installed on the server.
To create the file you need to do a workbook.SaveAs() call to save the workbook to a file.
Put a try/catch around the SaveAs to see if it is getting any error and log the error.

New Post: Does ClosedXML instantiate a new instance of Excel?

$
0
0

I already did that and there is no error. It works OK on my laptop (but then again, I have Excel – thus the reason why I thought it was req’d). I attached the snippet of code that does this. I have plenty of logging in it to trap any errors. None found.

var workbook =newXLWorkbook();

wsname = wsname + PayDate.ToString("MMDDYYYY");

fn = sFilePath + sNomenclature +".xlsx";

var worksheet = workbook.Worksheets.Add(wsname);

sql ="SELECT EmployeeID, PayDate, CostCenter4, CostCenter5, Costcenter6, Qty, PieceWork "+

"FROM WRFXUpld "+

"WHERE cast(PayDate as smalldatetime) >= cast(@PayDate as smalldatetime) "+

"ORDER BY EmployeeID, PayDate, CostCenter6, CostCenter5 ";

SqlConnection mySQLConnection =newSqlConnection(sConnectionString);

mySQLConnection.Open();

SqlCommand mySQLCommand =newSqlCommand(sql, mySQLConnection);

mySQLCommand.Parameters.Add("@PayDate",SqlDbType.Char);

mySQLCommand.Parameters["@PayDate"].Value = cPayDate;

try

{

string s15 ="Attempting to SELECT fields from WRFXUpld for the spreadsheet...";

Log(s15);

SqlDataReader mySQLReader = mySQLCommand.ExecuteReader();

string s16 ="Finished SELECT fields for the spreadsheet...";

Log(s16);

if (mySQLReader.Read())

{

string indcell ="";

int i = 1;

string s17 ="Going into loop to populate spreadsheet...";

Log(s17);

while (mySQLReader.Read())

{

indcell ="A"+ i.ToString();

worksheet.Cell(indcell).Value = mySQLReader["EmployeeID"].ToString().ToUpper().Trim();

string s17a ="In the spreadsheet loop for EmployeeID = "+ mySQLReader["EmployeeID"].ToString().ToUpper().Trim();

Log(s17a);

indcell ="B"+ i.ToString();

worksheet.Cell(indcell).Value = mySQLReader["PayDate"].ToString().ToUpper().Trim();

indcell ="C"+ i.ToString();

worksheet.Cell(indcell).Value = mySQLReader["CostCenter4"].ToString().ToUpper().Trim();

indcell ="D"+ i.ToString();

worksheet.Cell(indcell).Value = mySQLReader["CostCenter5"].ToString().ToUpper().Trim();

indcell ="E"+ i.ToString();

worksheet.Cell(indcell).Value = mySQLReader["CostCenter6"].ToString().ToUpper().Trim();

indcell ="F"+ i.ToString();

worksheet.Cell(indcell).Value = mySQLReader["Qty"];

indcell ="G"+ i.ToString();

worksheet.Cell(indcell).Value = mySQLReader["PieceWork"];

i = i + 1;

}

string s18 ="Finished looping to populate spreadsheet...";

Log(s18);

mySQLReader.Close();

mySQLReader.Dispose();

workbook.SaveAs(fn);

string s19 ="SAVED the spreadsheet!!!";

Log(s19);

}

else

{

string s20 ="No spreadsheet to save due to no data.";

Log(s20);

}

mySQLConnection.Close();

mySQLConnection.Dispose();

}

catch (Exception e4)

{

mySQLConnection.Close();

mySQLConnection.Dispose();

string s ="Unable to create spreadsheet due to: "+ e4.Message;

Log(s);

}

}

Thanks!

Mark Skinnell

ITP Sr. Project Manager

Office: 828-322-6261

www.itpbarcode.com

ITP logo tag1-small

New Post: Validation of cell using fixed List of values

New Post: Does ClosedXML instantiate a new instance of Excel?

$
0
0
You don't need Excel to use ClosedXML.

Put a log before and after workbook.SaveAs

New Post: Validation of cell using fixed List of values

$
0
0
Thanks, but this is not what I want to achieve. I do not want to specify a range inside the sheet as valid values, but just a list of fixed strings. As you can see in the screenshot it is possible in Excel, so I expect this can be done in ClosedXML as well. Unfortunately the documentation does not show how.

New Post: Does ClosedXML instantiate a new instance of Excel?

$
0
0
There is a log try before the SaveAs (actually right before the connection is closed & disposed) and then one right afterwards as shown below:

.
.
.
.
indcell = "F" + i.ToString();
worksheet.Cell(indcell).Value = mySQLReader["Qty"];
indcell = "G" + i.ToString();
worksheet.Cell(indcell).Value = mySQLReader["PieceWork"];

i = i + 1;

}

string s18 = "Finished looping to populate spreadsheet...";
Log(s18);

mySQLReader.Close();
mySQLReader.Dispose();

workbook.SaveAs(fn);

string s19 = "SAVED the spreadsheet!!!";
Log(s19);

}
else
{
string s20 = "No spreadsheet to save due to no data.";
Log(s20);
}

New Post: Does ClosedXML instantiate a new instance of Excel?

$
0
0
No clue but it has to be a server setup/configuration/environment thing.

New Post: Does ClosedXML instantiate a new instance of Excel?

$
0
0
I think I just found it!!! The specified directory needed to have a trailing '\' on it. Now it works! Thanks for the help!

Created Unassigned: Datetime text has been cuted! [9315]

$
0
0
I just find the text if like this "Tue 23/10/12", and i assign it to the value of the cell, it will automatically cut the "Tue" and it becomes "23/10/12".
and if the text is "6:00" it will automatically recognized as time format and set to "6:00:00".
This makes me very annoying ! How can i set the content as original as it is?

New Post: How to read two tables from Excel with C#?

$
0
0
Hi all. I have an exercise, to create a program with C# Windows Form, which could convert TWO tables from Excel to a single XML document. I have been writing this problem in about 7 forums (for example: http://www.dreamincode.net/forums/topic/345648-multiple-tables-conversion-from-excel-xls-file-to-xml-with-openxml/), but with no futher luck. But I get a comment, which advices me to use ClosedXML as my main library (I used pure OpenXML, which is very hard to learn and work with).

I was reading a documentation in here, but I didn't really get it, how to actually read two tables in Excel with C# using ClosedXML? My spreadhseet lokks like this:

Image

I need to read those TWO tables in C#, and when, basically, convert them to XML file.

So the question is how to read those two tables from Excel using C# ClosedXML library? Thank you.

New Post: How to read two tables from Excel with C#?

$
0
0
worksheet.Table(stringTableName)
worksheet.Table(int32TableIndex)
worksheet.Tables = collection of tables in the worksheet

Closed Unassigned: Datetime text has been cuted! [9315]

$
0
0
I just find the text if like this "Tue 23/10/12", and i assign it to the value of the cell, it will automatically cut the "Tue" and it becomes "23/10/12".
and if the text is "6:00" it will automatically recognized as time format and set to "6:00:00".
This makes me very annoying ! How can i set the content as original as it is?

Comments: This is the bane of my existence. In the beginning I tried to make ClosedXML behave as close to Excel as possible. That wasn't such a good idea after all. In your case the text is being converted to DateTime values (like Excel does). You have 3 options: #1 Format the date in the cells #2 Use cell.SetValue(string) instead #3 put an apostrophe at the beginning of the string e.g. '6:00'
Viewing all 1877 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>