Is it possible to export ASPxGridView with column which contains multiline text to excel using ASPxGridViewExporter?
I have an ASPxGridView with column that contains a multiline text.
When I export a grid's data using ASPxGridViewExporter that multiline text is rendered as one line (without line breaks).
I tried both <br/> and "\n" (newline) as line separators.
btw value of property PropertiesTextEdit-EncodeHtml is false on that column.
Thanks
There are 2 ways to achieve what you're looking for:
Specify WYSIWYG export type in XlsxExportOptionsEx:
XlsxExportOptionsEx options = new XlsxExportOptionsEx()
{
ExportType = DevExpress.Export.ExportType.WYSIWYG
};
ASPxGridView1.ExportToXlsx("Test.xlsx", options);
Tell the exporter you want to have data aware export and handle CustomizeCell event to set cell wrapping to true:
XlsxExportOptionsEx options = new XlsxExportOptionsEx()
{
ExportType = DevExpress.Export.ExportType.DataAware
};
options.CustomizeCell += options_CustomizeCell;
void options_CustomizeCell(DevExpress.Export.CustomizeCellEventArgs e)
{
e.Formatting.Alignment = new XlCellAlignment() { WrapText = true };
e.Handled = true;
}
Then use the customized options object for export.
See: https://www.devexpress.com/Support/Center/Question/Details/T381176
There is also the RenderBrick event which sometimes may be helpful. You may handle it like:
gveExporter.RenderBrick += gveExporter_RenderBrick;
void gveExporter_RenderBrick(object sender, DevExpress.Web.ASPxGridViewExportRenderingEventArgs e)
{
...
StringFormat sFormat = new StringFormat(StringFormatFlags.NoWrap);
BrickStringFormat brickSFormat = new BrickStringFormat(sFormat);
e.BrickStyle.StringFormat = brickSFormat;
...
}
But I have not found how to actually force cell wrap there, because StringFormatFlags has only NoWrap among suitable items. In my experience I did have cell wrapping long text in the exported Excel doc, so I've used RenderBrick to switch that wrapping off.
Hope that helps.
Related
After adding logic about creating price for object in grid it's always created "one line more" which is empty.
So, if there is need to be created two lines, it will be created 3 lines and that one addition will be empty.
Is there something what I missing in code?
[Control("CommandButton")]
class AreaActionPaneNew
{
void clicked()
{
PMCParameters contractParameters = PMCParameters::find();
PMETmpRentalObjectArea groupedAreaList; // Group by area_type and cost_type
PMERentalObjectPrice priceList;
date workingDate = currWorkingDate.dateValue();
;
super();
// Get grouped area values. Values are summed up by area_type and ancost_type
groupedAreaList = PMERentalObjectAreaCl::getRentalAreaPrCostType(pmeRentalobject.RentalObjectId, userSetting.validFrom(), userSetting.validTo() , workingDate);
ttsbegin;
while select groupedAreaList
{
select forupdate firstonly priceList
where priceList.RentalObjectId == pmeRentalObject.RentalObjectId &&
priceList.RentalCostType == groupedAreaList.RentalCostTypeId &&
priceList.AreaType == groupedAreaList.Areatype && priceList.ValidFrom == pmeRentalObject.ValidFrom;
if (!priceList)
priceList.initValue();
priceList.RentalObjectId = pmeRentalObject.RentalObjectId;
priceList.RentalCostType = groupedAreaList.RentalCostTypeId;
priceList.ValidFrom = pmeRentalobject.ValidFrom;
priceList.AreaType = groupedAreaList.Areatype;
priceList.Amount = groupedAreaList.Price;
priceList.Area = groupedAreaList.AreaValue;
priceList.Quantity = groupedAreaList.RentalQty;
if (!priceList)
priceList.Period = contractParameters.ReportPeriod;
if (priceList)
priceList.update();
else
priceList.insert();
}
ttscommit;
pmeRentalObjectPrice_ds.research();
}
}
The code looks like it only updates/inserts without creating a blank line.
From your attribute, you are using a Command Button (see here), which may have an associated command, such as New, which effectively pushes Ctrl+N, and would explain why you have a blank line.
The simplest way to check is just create a regular Button and override the clicked method, then copy/paste your code and push both buttons and see if they have different behavior.
Check the Command property on the button and see if there's something there. Try commenting out the super(); call.
You should perhaps consider just a Button or a Menu Item Button with an associated object.
I am required to replace a word with a new word, selected from a drop-down list by user, in a PDF document in ASP.NET. I am using iTextSharp , but the new PDF that is created is all distorted as I am not able to extract the formatting/styling info of the PDF while extracting. Also, IS There a way to read a pdf line-by-line? Please help..
protected void Page_Load(object sender, EventArgs e)
{
String s = DropDownList1.SelectedValue;
Response.Write(s);
ListFieldNames(s);
}
private void CreatePDF(string text)
{
string outFileName = #"z:\TEMP\PDF\Test_abc.pdf";
Document doc = new Document();
doc.SetMargins(30f, 30f, 30f, 30f);
PdfWriter.GetInstance(doc, new FileStream(outFileName, FileMode.Create));
doc.Open();
BaseFont bfTimes = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1252, false);
Font times = new Font(bfTimes, 12, Font.BOLDITALIC);
//Chunk ch = new Chunk(text,times);
Paragraph para = new Paragraph(text,times);
//para.SpacingAfter = 9f;
para.Alignment = Element.ALIGN_CENTER;
//para.IndentationLeft = 100;
doc.Add(para);
//doc.Add(new Paragraph(text,times));
doc.Close();
Response.Redirect(#"z:\TEMP\PDF\Test_abc.pdf",false);
}
private void ListFieldNames(string s)
{
ArrayList arrCheck = new ArrayList();
try
{
string pdfTemplate = #"z:\TEMP\PDF\abc.pdf";
//string dest = #"z:\TEMP\PDF\Test_abc.pdf";
PdfReader pdfReader = new PdfReader(pdfTemplate);
string pdfText = string.Empty;
string extracttext = "";
for (int page = 1; page <= pdfReader.NumberOfPages; page++)
{
ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy();
PdfReader reader = new PdfReader((string)pdfTemplate);
extracttext = PdfTextExtractor.GetTextFromPage(reader, page, its);
extracttext = Encoding.Unicode.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.Unicode, Encoding.Default.GetBytes(extracttext)));
pdfText = pdfText + extracttext;
pdfText = pdfText.Replace("[xyz]", s);
pdfReader.Close();
}
CreatePDF(pdfText);
}
catch (Exception ex)
{
}
finally
{
}
}
You are making one wrong assumption after the other.
You assume that the concept of "lines" exists in PDF. This is wrong. In Text State, different snippets of text are drawn on the page at absolute positions. For every "show text" operator, iText will return a TextRenderInfo object with the portion of text that was drawn and its coordinates. One line can consist of multiple text snippets. A text snippet may contain whitespace or may even be empty.
You assume that all text in a PDF keeps its natural reading order. This should be true for PDF/UA (UA stands for Universal Accessibility), but it's certainly not true for most PDFs you can find in the wild. That's why iText provides location-based text extraction (see p521 of iText in Action, Second Edition). As explained on p516, the text "Hello World" can be stored in the PDF as "ld", "Wor", "llo", "He". The LocationTextExtractionStrategy will order all the text snippets, reconstructing words if necessary. For instance: it will concatenate "He" and "llo" to "Hello", because there's not sufficient space between the "He" snippet and the "llo" snippet. However, for reasons unknown (probably ignorance), you're using the SimpleTextExtractionStrategy which doesn't order the text based on its location.
You are completely ignoring all the Graphics State operators, as well as the Text State operators that define the font, etc...
You assume that PDF is a Word processing format. This is wrong on many levels, as is your code. Please read the intro of chapter 6 of my book.
All these wrong assumptions almost make me want to vote down your question. At the risk of being voted down myself for this answer, I must tell you that you shouldn't try to "do the same". You're asking something that is very complex, and in many cases even impossible!
I have a xtragrid with values from a stored procedure.
I am getting the values in float (0.23) and I want to display in percent (23%).
What would be the best way to do it in C#?
before
after
Use CustomDrawCell event if you just want to display the cell readonly. or You can use the CustomColumnDisplayText Event also.
Try this:
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
if (e.Column.FieldName == "Marks")
{
e.DisplayText = (((int)(Convert.ToDecimal(e.CellValue) * 100))).ToString() + "%";
}
}
Another way use the Editor EditFormat and DisplayFormat property. and after setting these properties add it to the gridview column: Ref: How to format values shown in the XtraGrid
RepositoryItem textEdit;
private void AddGridRepositoryItem()
{
textEdit = new RepositoryItemTextEdit();
textEdit.AllowHtmlDraw = DevExpress.Utils.DefaultBoolean.True;
textEdit.ReadOnly = true;
gridControl1.RepositoryItems.Add(textEdit);
textEdit.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
textEdit.DisplayFormat.FormatString = "p";
gridView1.Columns[0].ColumnEdit = textEdit;
}
The simplest way is use GridColumn.DisplayFormat Property.
colPayment.DisplayFormat.FormatType = FormatType.Numeric;
colPayment.DisplayFormat.FormatString = "p0";
Hope this help..
Please use the following approach:
colReabilitation.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
colReabilitation.DisplayFormat.FormatString = "p0";
Related links:
GridColumn.DisplayFormat
Formatting Values
Standard Numeric Format Strings(MSDN)
i have this code
MasterSoapClient sp = new MasterSoapClient();
MasterData[] lstMasterData = sp.GetActivityType(stid, null, 1);
grdEditActivityType.DataSource = lstMasterData;
grdEditActivityType.DataBind();
Session["opType"] = 2;
txtActivityCode.Text = lstMasterData.ToString();
txtActivityCode.DataBind();
here i called web service and put all data in this Gridview "grdEditActivityType "
and already workin
but there is column of lstMasterData i want to put it in the text box out of the grid
how i can do this ?
txtActivityCode.Text is a Property that you can use to assign a text value to the TextBox.
If you use txtActivity.Text = " some input "; Your textbox will contain the text " some input ".
You don't need to Bind txtActivityCode afterwards.
Having this clarified the next step is to create the string you want using to assign to the text box.
string s = "";
foreach( var masterData in lstMasterData )
{
s += masterData.SomeProperty; // s += masterData.ToString(); maybe, it depends on what do you want to put in the textbox;
}
txtActivityCode.Text = s;
And that's all.
I would suggest to start look more over ASP.NET tutorials to understand better how this framework works.
i have a problem where i want to remove the last character from a textfield (including linebreaks) that has multiple textformats without removing the formats.
so far i have:
textfield.replaceText(textField.length-1,textField.length-1,'');
i guess this doesn't remove linebreaks, and is very slow, seems to destroy my textformats.
or:
textfield.text = textfield.text.slice(0,-1);
this is faster but removes all textformats as well.
It is a bit tedious, but you can use the htmlText-property of TextField, even though you are not formatting your text with StyleSheets: Flash will transform all your formatting information into HTML text internally, so even though you set textField.text, you can still get xml formatted text to work with:
textField.text = "A test.";
trace (textField.htmlText);
will actually return:
<P ALIGN="LEFT"><FONT FACE="Times Roman" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">A test.</FONT></P>
Text will always appear within <FONT> tags reflecting the changes you made using setTextFormat(). You can, therefore, iterate over the XML contained in this line, and remove only the last character in the last TextNode:
private function removeLastCharacter (textField:TextField) : void {
var xml:XML = new XML (textField.htmlText);
for ( var i : int = xml.children().length()-1; i >= 0; i-- ){
var node:XML = xml.children()[i];
if ( node.name() == "FONT") {
var tx:String = node.text()[0].toString();
node.setChildren (tx.substr (0, tx.length-1));
break;
}
}
textField.htmlText = xml;
trace (textField.text); // In the above example, output will be: "A test";
}
I hope I understand your problem correctly. If you keep your formatting in htmlText, I have one possible solution:
The idea is to keep the formatted text in an XML format, and modify the XML. XML will keep your formatting intact, you don't have to do string aerobatics to maintain them. The downsides are of course having to keep the formatting XML valid, and the extra variable.
Here's an example:
var tf:TextField = new TextField();
var t:XML = new XML("<html><p>lalala</p><font color='#ff0000'> lol</font></html>");
tf.htmlText = t.toXMLString();
t.font[0] = t.font[0].text().slice(0, -1);
tf.htmlText = t.toXMLString();
addChild(tf);