PDA

View Full Version : alt enter simulation in qstring



Dilshad
28th December 2010, 06:51
Hello,
I have a log file which has the extension .txt.
The log file has tab separated values, so it can be opened with excel.
I append the error found in the QString and then display it in a cell.
I need to display the errors in the same cell one below another just like it is done with alt+enter.
Is there any way that I can append alt+enter to the QString itself so that when I open the .txt in excel, the string is represented in the cell one below another.

Thank you in advance.

tbscope
28th December 2010, 08:09
Adding a single line feed character will probably work.

Dilshad
28th December 2010, 08:35
Thanks for the reply, but I already tried appending "\n" to the string and also "\r\n", but that causes the string to be printed in the cell in the next row, not in the same cell.

wysota
28th December 2010, 09:55
Format the file as csv and not plain text. Then you'll be able to use csv rules for appending newlines to cell values. Excel will import that without a problem.

nroberts
28th December 2010, 17:35
Hello,
I have a log file which has the extension .txt.
The log file has tab separated values, so it can be opened with excel.
I append the error found in the QString and then display it in a cell.
I need to display the errors in the same cell one below another just like it is done with alt+enter.
Is there any way that I can append alt+enter to the QString itself so that when I open the .txt in excel, the string is represented in the cell one below another.

Thank you in advance.

I'm 99.999999% sure that excel won't ever respond to anything you might come up with in the way you're expecting. In UI programs like excel, Alt+Enter is not a character code in the string, it's a key code in an event that the UI responds to by moving focus to a different cell (or whatever)--Alt+Enter doesn't even result in a character code at all so even if excell does do it, it does it itself in its own special way. This difference in cell is then saved in some special way by the program. Your best, and probably only bet, is CSV like wysota mentioned or an actual excel file format. The former being almost certainly the easier way.

squidge
28th December 2010, 18:28
I know CSV will work as I've done it before, however it probably will not be what you want because of the limitations of the CSV file format. You can use multiple lines by including a linefeed (0x0A) character in the quoted string for that column, but the column will only be the height of a single line so you will not see this extra data until you manually (in excel) resize that row, or edit the data to automatically resize the row. You can't include this row-height property in the CSV file.

I would therefore suggest you use XML file format. For example:



<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
</Style>
<Style ss:ID="s21">
<Alignment ss:Vertical="Bottom" ss:WrapText="1"/>
</Style>
</Styles>
<Worksheet ss:Name="Book1">
<Table ss:ExpandedColumnCount="5" ss:ExpandedRowCount="1" x:FullColumns="1"
x:FullRows="1">
<Row>
<Cell><Data ss:Type="String">a</Data></Cell>
<Cell><Data ss:Type="String">b</Data></Cell>
<Cell ss:StyleID="s21"><Data ss:Type="String">c
line 2</Data></Cell>
<Cell><Data ss:Type="String">d</Data></Cell>
<Cell><Data ss:Type="String">e</Data></Cell>
</Row>
</Table>
</Worksheet>
</Workbook>


Note the use of a different style for the cell where you wish to include an embedded linefeed. Without this, the line feed character will be parsed incorrectly and you'll just see a square box.

EDIT: Hmm, it seems the forum software has converted the "&#10<semicolon>" into an actual line feed. If you wish to try this XML file out, you may wish to change that back, or just download this attachment: 5656

Dilshad
29th December 2010, 05:59
Thanks Everyone,
@squidge I will try the solution. Thanks.