How to write true/false in capitalize in excel via c# - c#

whenever i write true/false in excel via c#. it shows and convert it into uppercase "FALSE/TRUE" in excel.
what should i do to remain it's case sensitivity?
I've tried with single quote " ' ", it shows what we want but logically it holds the value of single quote as well. ex: " 'False " in excel shows as False , but in data it shows 'False .
Is there any property changes, custom settings or via c# code can do this for me?
I'm writing data via c# DataTable to Excel worksheet cells in this manner.
for (int i = 0; i < dtToExport.Rows.Count; i++)
{
for (int j = 0; j < dtToExport.Columns.Count; j++)
{
workSheet.Cells[(i + 2), (j + 1)] = dtToExport.Rows[i][j];
}
}

Related

syncfusion xlsio change column type from text to number

I have a .xlsm file which I get from a web page. This file is an exported database, and it has numeric data written as text, numeric information that can't be used in formulas because excel thinks it is a text.
Which would be the most efficient way to convert the column data type from text to number?
Right now I have been only capable of doing it with a for loop, but this files can have up to 10.000 registers.
for (int i = 2; i <= 10002; i++)
{
sheet.Range["A"+i.ToString()].Number = sheet.Range["A" + i.ToString()].Text;
}
I also tried with numberformat property, but it doesn't seem to be related
sheet.Range["A2:A10002"].NumberFormat = "#";
Here is an example of the Excel file.
https://drive.google.com/file/d/1Kz98NDYsj7k7zCmGyl-ohz_VErnsyGvV/view?usp=sharing
Syncfusion XlsIO doesn’t support Microsoft Excel’s Convert to Number option when Number Stored as Text. And, there is no other efficient way to get this achieved except looping and setting the number format as below.
Code snippet:
for (int i = 2; i <= 10002; i++)
{
double value;
string rowString = i.ToString();
if (double.TryParse(sheet.Range["A" + rowString].Value, out value))
{
sheet.Range["A" + rowString].Number = value;
sheet.Range["A" + rowString].NumberFormat = "0";
}
}
Note: I work for Syncfusion.

DateTimePickers don't show the data

The database contains data about movie house(cinema's). The database contains this fields : Name of movie house, Name of movie, start time and date.
I have a problems with additional task. The program should generate a report for each
cinema in the order of the sessions on the specified date.
When I choosing a date in DatePickers, database doesn't show the first movie.
Example:
value of datetimePicker1 = 13.12.2018
value of datetimePicker2 = 16.12.2018
that database show information about 14,15,16.12.2018.
for (int i = 0; i < tableDataGridView.Rows.Count - 1; i++)
{
if (Convert.ToDateTime(tableDataGridView.Rows[i].Cells[4].Value) >= dateTimePicker1.Value
&& Convert.ToDateTime(tableDataGridView.Rows[i].Cells[4].Value) <= dateTimePicker2.Value)
MessageBox.Show(tableDataGridView.Rows[i].Cells[0].Value.ToString() +
" || Movie theater: " + tableDataGridView.Rows[i].Cells[1].Value.ToString() +
" | Movie: " + tableDataGridView.Rows[i].Cells[2].Value.ToString());
}
Please make a change:
I was able to create a similar C# WindowsFormsApplication based on information you have provided and was able to replicate a similar bug and got it resolved with this:
Change:
for (int i = 0; i < tableDataGridView.Rows.Count - 1; i++)
To:
for (int i = 0; i < tableDataGridView.Rows.Count; i++)
Second:
If there is a blank line at the end of GridView, then you may need to add this line to Form1_Load event
tableDataGridView.AllowUserToAddRows = false;

Copy Excel cell comments in a specified range

What is the way to copy all cell comments (on right click - Insert Comments) in a specified range?
Range r1 = (Range)ws1.get_Range("A1", "C10");
Range r2 = (Range)ws2.get_Range("A1", "C10");
r2.Value = r1.Value; // copies cell values and ignores comments
I know that r1.Copy(r2); would copy values and comments, but it shows unnecessary Excel dialogs due to validation issues and therefore I cannot use it.
There's a AddComment method for Range. Unfortunately, it cannot be applied to a range of cells. I guess they assumed: why would you want the same comment written multiple times? So you'll have to loop:
for (int r = 1; r <= r1.Rows.Count; r++)
{
for (int c = 1; c <= r1.Columns.Count; c++)
{
r2[r, c].AddComment(r1.Comment);
}
}

Faster way to find empty cells and Cells containing specific string in Excel 2013

While creating and customizing Excel file using Interop and Office 2013 installed, gives me somehow extremely slow results (more than 5 minutes).
In fact, the same thing works very well on Excel 2010 interop (just 50 seconds, exactly same process). (Code snippet below)
It would be nice to know if there is a faster way to do this. I know there are different libraries to do this but I would like to stick to Interop since everything is already in the same.
I am creating Excel file first then check if there are any empty cells or cells containing a specific string and change color of those cells.
To create Excel, I used Object array and parse it that is really faster. Main thing which is pulling it down is to search and change cell color.
// Check for empty cell and make interior silver color
for (int row = 0; row < rowNo; row++)
{
for (int col = 0; col < columnNo; col++)
{
if (string.IsNullOrEmpty(objData[row, col].ToString()))
{
// Access that cell in Excel now and change interior color
Range cell = (Range)activeSheet.Cells[row + 2, col + 1];
cell.Interior.Color = System.Drawing.Color.Silver;
}
}
}
// Check for cells contains "column header string#"
for (int col = 16; col < columnNo; col++)
{
// Get column header - only once and use it for all rows in the same column
string cellValue = activeSheet.Cells[1, col + 1].Value2.ToString();
for (int row = 0; row < rowNo; row++)
{
string value = objData[row, col].ToString();
if (string.IsNullOrEmpty(value) || value.Contains(cellValue+"#"))
{
Range cell = (Range)activeSheet.Cells[row + 2, col + 1];
cell.Interior.Color = System.Drawing.Color.Silver;
cell.Font.Color = System.Drawing.Color.Red;
}
}
}
I'd look into selecting the whole range and setting conditional formatting so blank cells are the color you want. Sorry don't have any code for you, it's been awhile since I've played in that realm.

Export the tables from pdf to excel?

How do i export only the table contents to excel file through C# programming?
I am currently extracting all the contents from PDFs using PDFNET SDK ,but couldn't able to read the table as a tabular structure
I know have not used the SDK for this product, but I have used the stand alone product. It read the content of a PDF into a spreadsheet (many export options).
The product is OmniPage by Nuance http://australia.nuance.com/for-business/by-product/omnipage/index.htm.
there is an SDK with free evaluation.
Using bytescount PDF Extractor SDK we can be able to extract the whole page as below,
CSVExtractor extractor = new CSVExtractor();
extractor.RegistrationName = "demo";
extractor.RegistrationKey = "demo";
TableDetector tdetector = new TableDetector();
tdetector.RegistrationKey = "demo";
tdetector.RegistrationName = "demo";
// Load the document
extractor.LoadDocumentFromFile("C:\\sample.pdf");
tdetector.LoadDocumentFromFile("C:\\sample.pdf");
int pageCount = tdetector.GetPageCount();
for (int i = 1; i <= pageCount; i++)
{
int j = 1;
do
{
extractor.SetExtractionArea(tdetector.GetPageRect_Left(i),
tdetector.GetPageRect_Top(i),
tdetector.GetPageRect_Width(i),
tdetector.GetPageRect_Height(i)
);
// and finally save the table into CSV file
extractor.SavePageCSVToFile(i, "C:\\page-" + i + "-table-" + j + ".csv");
j++;
} while (tdetector.FindNextTable()); // search next table
}
since it is an old post, hope it would help others.
Above answer(John) works,it is really useful.
But i use bytescount PDF Extrator SDK tools instead of using code.
By the way,the tool will generate a lot of sheet in one excel file.
You can use code below in excel to generate as one sheet.
Sub ConvertAsOne()
Application.ScreenUpdating = False
For j = 1 To Sheets.Count
If Sheets(j).Name <> ActiveSheet.Name Then
X = Range("A65536").End(xlUp).Row + 1
Sheets(j).UsedRange.Copy Cells(X, 1)
End If
Next
Range("B1").Select
Application.ScreenUpdating = True
MsgBox "succeed!", vbInformation, "note"
End Sub

Categories

Resources