Translate/Rename "Values" column labels in pivot table created using closed xml - c#

I am creating a pivot table using Closed XML. My multilingual application generates an excel sheet(pivot table) with some source data based on my language chosen. I want to translate my excel's columns and other details to English/other language . As shown in the image I want a way to translate "Values" column labels. Or if I can rename "Values" as per my selection of language, if translation is not possible.
I tried the following -
ptSheet.Cell(5, 5).Value = langId == 0? "Values" : "Data";
But once I generate the excel, a popup shows up for reloading the data and then excel is generated with column label as "Values" only.

Related

How to get the data in the column from c# winform to gridview header

I am a developer who is developing winform with c#.
The key to the question is to put data corresponding to the gridview header.
First, the data contained in the column is classified by some criteria in the procedure of mssql.
Up to this point, it is classified as a checklist of winform.
I would like to put this classified data in the banded gridview header among the gridviews supported by devexpress.
The problem is that you have to put the column data in the mssql into the header.caption of the view, but you are unable to get the column.
And there are a total of 12 headers for column data, but we can't find a way to handle it dynamically.
The way I tried was to bring the column name into a variable and get the data from the dictionary.
//QUERY
SELECT #TEST = B.TEST
FROM TABLE A
JOIN TABLE2 B ON A.COLUMN = B.COLUMN
// CODE
dicParam["#TEST"] = headerName.caption; //result : null ..
Please help me. Please.

How to generate product receipt in winform application?

I am working on a winform application for the first time and I have a gridview which contains a list of products users have bought.
I have a Print button on click which allows the user to generate a receipt like the one below:
So here I am confused whether I should use "winform default RDLC or Crystal Report" or whether I should generate PDF and then let it print out as receipt, but I am not sure if PDF is a good option for receipt generation or not.
For Crystal Report, I have read that I need to install it and client (who will use this desktop application) had to install Crystal Report and also there is some licensing involve with Crystal Report which I don't want.
Also if I use Crystal Report then I am not sure if it would be possible to generate exactly above receipt (with table formatting) and will it be complicated?
Receipt is bit complicated so is there a better tool or way, or how should I generate receipt I have shown in above image?
Update : Printing paper total size is : 7.50 centimeter and user wants to print all the content in center.
Discount = FinalAmount - MRP;
Customer Name, Mobile No, Bill No, Payment Mode values are entered on the form by user itself.
I am having a Excel file which contains list of products and with each products I have information like ProductId,ProductName,MRP,Tax information like CGST,SGST.
Code to fill gridview from excel file based on Product Id:
using (OleDbConnection cnnxls = new OleDbConnection(strConn))
using (OleDbDataAdapter oda = new OleDbDataAdapter(query, cnnxls))
{
oda.Fill(dtProductList);
DataColumnCollection columns = dtProductList.Columns;
if (!columns.Contains("FinalAmount"))
{
dtProductList.Columns.Add(new DataColumn() { ColumnName = "FinalAmount", DataType = typeof(decimal) });
}
if (!columns.Contains("Quantity"))
{
dtProductList.Columns.Add(new DataColumn() { ColumnName = "Quantity", DataType = typeof(int) });
}
DataRow lastRow = dtProductList.Rows[dtProductList.Rows.Count - 1];
lastRow["FinalAmount"] = Convert.ToDecimal(lastRow["MRP"]);
lastRow["Quantity"] = 1;
}
Generate and print the receipts
You can use any report designer tool like RDLC Reports or Crystal Reports to generate a report. RDLC reports are good enough. You can print the RDLC report with or without showing the print dialog. You can also easily export the RDLC report manually or using the code.
If for any reason you don't want to use a reporting tool, as another option you can consider generating HTML report easily using Run-time T4 templates.
Using an RDLC report, how to show multiple fields in a single cell
You can easily use an expression to show multiple values in a single cell. Also as another option, you can use rows in a single row group and show different fields in a single column.
Example 1 - RDLC - Show multiple fields in a single column using expression
The following steps show you how you can display multiple fields in a single column using expression. I assume you have set up the data source and have ProductName, UnitPrice and Quantity fields. Then, follow these steps:
Drop a Table from toolbox on the report design surface.
In first column, first data row (not the header row), right click and choose ProductName (image)
Select the header of the second column and type UnitPrice/Quantity (image)
In second column, first data row, right click and choose Expression. (image)
In the expression window, enter the desired expression, for example:
= "UnitPrice: " & Fields!UnitPrice.Value.ToString() & System.Environment.NewLine & "Quantitye: " & Fields!Quantity.Value.ToString()
Example 2 - RDLC - Show multiple fields in a single column using row group
The following steps show you how you can display multiple fields in a single column. I assume you have set up the data source and have ProductName, UnitPrice and Quantity fields. Then, follow these steps:
Drop a Table from toolbox on the report design surface.
In first column, first data row (not the header row), right click and choose ProductName (image)
Select the header of the second column and type UnitPrice/Quantity (image)
Right click on row header of the first data row and choose Insert Row → Inside Group - Below (image)
In second column, first data row, right click and choose UnitPrice. (image)
Click on the [UnitPrice], and then press Home and type UnitPrice: (image)
Do the same for Quantity, in the next row in the group.
If you need another row in the group, repeat step 3.
You can setup borders of the cells by selecting them and setting BorderStyle individually for top, left, bottom and right.
Download
You can clone or download an example using expression here:
repository
zip file
A quick and easy way I used before was to generate a html page, and then use the html2pdf library to convert it to a pdf file.
You may also consider this approach since the RDLC reports/Crystal reports may be a overkill for your case.
The RDLC is powerful as well as Crystal reports. You may choose the rdlc which comes close in eliminating licensing costs.
Using RDLC
Data
You need to add datasets Here or data sources to the report which you will manipulate to meet the design and data you want.
Design
On design you just drag and drop controls to your taste. There is a challenge that sometimes what you see on the design may not what be you see on final output so you need to test much.
Printing
You can put a print preview or send directly to a pdf viewer using rdlc. Here is an example.
Conclusion
I think If you have your data generated well on the report, the design and layout won't be much of a problem using both rdlc and crystal reports.
UPDATE
Based on further information provided I have tried to do something that may come close to what you want to achieve.
I have used crystal reports as well as database table to simulate because of time. Otherwise the same can be achieved using rdlc.
The sample table i created
Here is the sample query and results from the database. I have made groups that can be accomodated by the crystal reports. You can do calculated text values using the same to put distinction between the Tax information as well as Transaction Memo.
Here is the final look after tweaking the design. The page layout may also be tweaked with regards to your taste.
Update.
For RDLC I think you need to add datasets for memo data and tax information. Take a look at the below if it comes close. I failed to make a preview there were components I hadn't installed.
for adding 3 columns in one cell
you have two options:
1- Use new line expression
=Fields!MyField1.Value + System.Environment.NewLine + Fields!MyField2.Value
2- Use something like subreport or grouping in rdlc.
the first option seams easier

Export HTML elements to Excel in C#

I have a requirment is to export data from DB table to Excel. I'm using MVC project where from View the user click a button to call a controller action to perform the export opertaion. The DB proc returns rows where couple of columns contains HTML data like
<ul><li>Name1</li><li>Name2</li></ul>
and this should be shown in Excel cell as below
Name1Name2
How can i do this ? any kind of help is deeply appreciated.
To recap the comments:
In general it's not possible to apply any styling via code (VBA or C#) that cannot be applied through the Excel interface.
Styling possibilities in Excel are quire limited, you can set font properties (size, weight, font, etc) by character, but 'paragraph' formatting can only be set per cell if at all.
Things that can be set per cell are alignment and indent (and text wrapping)
In order to simulate the bullet list, you could use VBA code like this:
Cells(1, 1).Value = Chr(149) & " foo" & vbCrLf & Chr(149) & " bar"
Cells(1, 1).IndentLevel = 2
C# code would be very similar.
But this is as good as it gets, doing anything more complicated in a single cell is unfortunately not possible. If you have to use Excel, I suggest you have just single paragraph per cell.

How to add items to the Rdlc report dynamically?

I have a service that returns a json concatinated string. I want that binded to the rdlc reportviewer to generate report.
In that concatinated string, I have 5 strings that will compose of dynamic data which we cannot estimate how many records it will contain coming from 5 different tables.
These 5 should be binded to 5 tables on report. The last string is composed of constant values that have to be binded to the table or textboxes as a parameter.
There is no option to dynamically add the items to RDLC report. You can create data set from the concatinated string and set that dataset as datasource for RDLC report. In RDLC report you can add 5 different tables or matrix to show up these data.
You said, for fifth table you need to show it in textbox. It is not possible to show in text box. you have to use table or matrix for that.
Or else, RDLC report is just a XML structure. Your need to create your own RDLC report based on the input data dynamically. You can find RDLC specification here http://msdn.microsoft.com/en-us/library/dd297486%28SQL.100%29.aspx

bind multiple rows to a textbox for edit + update

I have created a Windows form using Visual C# - this contains a rich textbox. I have an Access database containing text in 2 cells (rows) of 1 column.
What I want to be able to do is:
Concatenate the contents of rows within my Access table
Display the concatenated rows in the rich textbox on my form
Be able to edit the contents of the rich textbox and save the changes back to the table
So far I have bound the table to the rich textbox, though only 1 cell (row) is being displayed - the data that I will be concatenating is text, each cell in the table won't have a unique value - each cell simply holds a section of a paragraph.
I have read the Update command & Retrieve command of ADO.Net, though it seems that data must have a specific value i.e. Select Name from People where value = Peter
Is there a chance of me achieving what I want to achieve here?
No.
Instead, I would store each value in a separate column in the database, and then bind each textbox to that field.

Categories