Passing value in IXLWorksheet convert string to date - c#

I have an excel builder with IXLWorksheet.
When I try to pass the values decimal to the excel worksheet, it convert thes numbers 3.10,3.11 and 3.12 into date.
I really don't have an idea why is this happening, someone know?
Print Example:
4.30 converts normal
3.10 turns into datetime.

I used this to resolve:
ws.Cell(vLinha, coluna).SetValue(Convert.ToString(propertyValue));

Related

Crystal report converting DateTime to string Too many arguments have been given to this function

I have a simple formula like below in crystal report:
iif(isnull({employ.createdDate}),"", ToText({employ.createdDate}, "dd-MMM-yyyy"))
The {employ.createdDate} is in below format:
02/09/2015 10:48:25
It works fine when {employ.createdDate} is null, but when it's not null, the below error message shows:
Too many arguments have been given to this function
Error in File employeeInfo.rpt:
Error in formula txtDate
Removing the "dd-MMM-yyyy" does solve the problem but I would like to format the date to "dd-MMM-yyyy" format i.e. "09-FEB-2015"
What's wrong with the formula?
Oh I figured it out...
The 02/09/2015 10:48:25 is in string format, so I need to convert it to date and convert it to string, I modified the formula to this, and it works:
ToText(cDate({employ.createdDate}),"dd-MMM-yyyy")
Try using this instead of just toText
iif(isnull({employ.createdDate}),"", ToText(cDate({employ.createdDate}),"dd-MMM-yyyy"))

Format Entire Excel Column Using C#

I have column F that I want to format as money so add $ sign and commas. It's to late for me to attempt to format it in the Source so I was going to format it via C# after all data has been written to Excel. I know you can use this syntax to change a column to a date - what would be the appropriate syntax for money?
range.EntireColumn.NumberFormat = "MM/DD/YYYY";
Sorry for my stupidity on this one...it's actually quiet simple
range3.EntireColumn.NumberFormat = "$#,##0.00";

Excel format function equivalent in c#

I have an application that uses excel. The user needs to write an excel format in my application and I need to place it excel to some cells. However I need to provide an example to the user to know if the format will be correct or not.
I know in VBA there is the function FORMAT. Is there an equivalent in C# for this function?
It needs to work for example with the format "[$-409]d.m.yy h:mm AM/PM;#" but it has to support anything that the Excel supports.
This was bothering me too. I didn't want to have to apply NumberFormat to the cells, paste the values and then retrieve the text.
After some investigation, I found the function that does this.
WorksheetFunction.Text: https://msdn.microsoft.com/en-us/library/office/ff841121.aspx
The first argument is the value that you want to format, this could be a String, DateTime, Double, Integer etc, the second argument is the Excel NumberFormat string.
MessageBox.Show(ExcelApp.WorksheetFunction.Text(DateTime.Now, "[$-409]d.m.yy h:mm AM/PM;#"));

Converting a Numeric value fetched from a Dataset to a String Asp.net c#?

I have a numeric value like this in my db,
14192555.00
when i get it and put it in text box and convert it in to string it results in,
this.txtPriorNYSDOTRating.Text = ds.Tables[0].Rows[0]["Fact2A_PriorNYSDOTPerfRatingScore"].ToString();
14192555.0000
for it formatting i also tried,
this.txtPriorNYSDOTRating.Text = ds.Tables[0].Rows[0]["Fact2A_PriorNYSDOTPerfRatingScore"].ToString("0.####");
it result in error "no overload for method string"
Hopes for your suggestion thanks in advance
EDITED:
i have date in database like,
2010-10-19 00:00:00.000
i get it like,
10/19/2010 12:00:00 AM
my code is,
this.txtDesignatedDate.Text =Convert.ToDateTime(ds.Tables[0].Rows[0]["DesignatedDate"]).ToString();
how to format it to get only `"10/19/2010"
Hopes for your reply
You need to convert it to double and then apply the format.
double d = Convert.ToDouble(ds.Tables[0].Rows[0]["Fact2A_PriorNYSDOTPerfRatingScore"]);
this.txtPriorNYSDOTRating.Text = d.ToString("0.####");
Currently it is of object type and that doesn't expose ToString overload with format parameter.

Prevent TestContext data from being automagically converted

I am parameterising my test cases by using data read from .csv files. One of the columns in the csv file has simple date values (as regular strings) in US format, eg mm/dd/yyyy. When the data is actually read and populated into a TestContext however, TestContext.DataRow["MyDateColumn"] actually returns a converted System.DateTime object, complete with a timestamp of 12:00:00 AM. I absolutely do not require or want this automatic conversion. How do I stop this from happening?
If the type of the MyDateColumn is set to datetime, then it would/should return a datetime object.
Try changing the type of MyDateColumn to be string and see if that does the trick.
UPDATE
Change dates in the CSV so that they are "mm/dd/yyyy" instead of mm/dd/yyyy.
DateTime.Parse(TestContext.DataRow["MyDateColumn"], CultureInfo.InvariantCulture).ToShortDateString()
I got solution for this :)
I just put ' before actual data. When I retrieve data, data comes as is. Before using it, I remove ' from data with substring method.
I remember using this technique on excel to make numbers appear as text. It worked for me.
I put double qoutes around the data. That gives back strings, without removing the quotes.
columnInt, columnString
1, "11.12.89"
2, "12.12.89"

Categories

Resources