openpyxl alignment indent vs ident - openpyxl

In my Excel file data in the cell is indented, and indent information is very important to get.
My code:
import openxlpy as opxl
wb = opxl.load_workbool('file.xlsx')
sh = wb.get_active_sheet()
r = sh.rows
c = r[10][0]
now the question:
c.style.alignment gives me two options (1) indent and (2) ident
(1) does NOT return correct indent information
(2) has correct number
what is the difference between the two? Is it normal for ident to have correct info.
thank you
[update]
openpyxl version is 1.8.5. Text is representing a tree, where each indent is next level. It starts with no indents and goes in increments of 1

I don't know what version of openpyxl you're using but ident has never been an alignment attribute. c.alignment is the preferred spelling. The specification defines indent thus:
An integer value, where an increment of 1 represents 3 spaces. Indicates the number of spaces (of the normal style font) of indentation for text in a cell. The number of spaces to indent is calculated as following:
Number of spaces to indent = indent value * 3
[Example:For example, an indent value of 1 means that the text begins 3 space widths (of the normal style font) from the edge of the cell.
end example]
[Note: The width of one space character is defined by the font. end note] Only left, right, and distributed horizontal alignments are supported.
The possible values for this attribute are defined by the W3C XML Schema unsignedInt datatype.

Related

How to have a text box contain a character position under each character

I have a text box on an MS-Access 2007 Form (its old, but its what I have) called text_record. I want to display the characters in the text box with a positional line directly underneath the text. e.g.
ABCDEF
123456
I used the following code to set the field:
dim x as string
x = Forms![mapped field names].Form![text_record] & vbcrlf
For i = 1 To Len(x) - 1
x = x & CStr(i Mod 10)
Next
Forms![mapped field names].Form![text_record] = x
The code works and shows the integer positions underneath, but the characters are not aligned directly above the numbers. I need the characters directly above the positional number so a user can see what is in a particular column.
I tried several different font types, all said they were monospaced, and they all fail to align directly above the number. Depending on the text in the record, the position was off as much as 5 columns.
I must be missing something simple.
Thanks in advance for any and all responses
Use a fixed font. Courier New is a fixed size.
So, on the form, I drop in a text box, and right below another text box
(I set the border to transparent, and I set enabled = false (so user can't edit, or tab into).
so we have this:
And the font for both text boxes is this:
And my code (it puts numbers below as you type).
Private Sub Text0_Change()
Dim sResult As String
Dim i As Integer
For i = 1 To Len(Text0.Text)
sResult = sResult & i Mod 10
Next i
Me.Text2 = sResult
End Sub
So, we see this (and I typed in "i" and "l", since they are small compared to numbers, and we get this:
so, not sure what font you used, but Courier new is a fixed font, and should work as per above.
You might be better off splitting the text and putting it into a multi-column list box.

SAP Smartforms dynamically change position of certain items

So I got this text of which I can't know the length beforehand because it depends on how many entries there are in an internal table (see below). The table is given to the Smartforms FM in my report. The text itself works fine with a dynamic text variable, but under that text I need a horizontal line. The Line needs to be right beneath the text at all time. So far I only got a line with a fixed position, which does not lead to the result I want.
If it is possible, how can I get the line to change position based on the length of the text? So that it is right under the text at all time, no matter how many lines the text got.
DATA: l_string TYPE string,
lt_stream_lines TYPE STANDARD TABLE OF string.
loop at i_tab.
* reading one line of i_tab into l_string.
APPEND l_string TO lt_stream_lines.
APPEND '' TO lt_stream_lines.
endloop.
CALL FUNCTION 'CONVERT_STREAM_TO_ITF_TEXT'
EXPORTING
stream_lines = lt_stream_lines
lf = 'X'
TABLES
itf_text = gv_text.
* gv_text then has the full text I want to display
You must have a Main Window containing your Text element followed by a dummy Template element for the horizontal line (one empty cell with the top horizontal border in black color and other borders transparent).
Create a Template element via the context menu:
Draw the border (here I exaggerate the proportions "a little bit"!):
Preview result:

I need the character (square form) which entirely filled the charactere area and there is no spaces between two of these characters

I need the square-symbolized character have the square shape that fills entire the character's area, (black).
Example: There where the character with (Alt + 196) ASCII code which is a line that horizontally filled the width of the character's space:
Here is 5 character of Alt + 196: ─────
So there is no space between characters.
I need this form for a squared character that fills the width and height of the characters space.
Regards.
Three Full block characters
ThisWorkbook.Worksheets("Sheet1").Range("A2") = String(3, ChrW(&H2588))
Horizontal Line (3 characters)
ThisWorkbook.Worksheets("Sheet1").Range("A3") = String(3, ChrW(&H2500))
ThisWorkbook.Worksheets("Sheet1").Range("A4") = String(3, ChrW(&H25AC))
The character is called the En Dash and it's code is 150. The way that I determined this is by using the Symbol Dialog to insert the it into a cell and then in the Immediate Window I used ?Asc(ActiveCell.Value) to get its Character Code. Chr(150) will reproduce the character and the String function can be used to repeat the it (e.g. String(5, 150) returns ───── ).

If content in a cell is too long, show "Multiple" instead of letting the text overflow in Excel

So, I have a custom function that concatenate different cells and put a comma between words.
For example, say I have "ABCD" "BC" then, this function will
output ABCD, BC. Now the problem is that the text will overflow in a cell and overlap with the cell next to that. In order to solve this problem,
I am thinking of just replacing the concatenated word with "Multiple" if more than 3 words are combined. Is there anyway to do this in a cell?
You can do this with conditional formatting AND keep the original underlying string as a raw value for other purposes.
Select the cells with the formula and create a conditional formatting rule based on a formula.         =LEN(C2)-LEN(SUBSTITUTE(C2, ",", ""))>1 
Click Format and go to the Numbers tab. Choose Custom from the list down the left side and supply the following for the Type:         ;;;[color13]_((\multipl\e)   I've opted to also make the font dark blue (colorindex # 13) and indent from the left.
Click OK to accept the formatting and then OK again to create the new rule.
        
As you can see in the sample image above, the underlying raw value remains (shown in the formula bar) but (multiple) is displayed.
More on custom number formatting codes at Number format codes

Word.Range : Move Range index in the formatted text that corresponds to the plain text

I need to analyze text of my Word document, and create bookmarks on range of text my analyzer has detected (almost like a grammar checker).
I don't want use Find() utility, because my needs are too specific.
Explanations
For that,
1/ Retrieve Document plain text
I Retrieve Plain text of the main story of my document :
String plainText = ActiveDocument.Range().Text;
2/ Analyze plain text and get results
I send it to my analyzer tool which return a collection of marker with position :
For example, if I wanted to detected the pattern "my pattern" in the document text, analyzer could return a marker as { pattern : "my marker", start: 5, end : 14 }, where "start" and "end" are the character indexes of the pattern in the plain text sent.
3/ Display results in Document
I create bookmark from theses markers
For previously example, it woold be :
// init a new range and collapse it
Word.Range range = activeDocument.Range(); range.Collapse(WdCollapseStart);
// move character-by-character in the "formatted" text
range.MoveStart(WdUnits.Character, Marker.start ); # Marker.start=5
//set length (end)
range.setRange(range.Start,range.Start+(Marker.End-Marker.Start)); #Marker.end=14
4/ Results
4.1 Global Result
Everything is OK when Document Main Story Contains Text, links, lists, titles :
Ranges are well positionned, Plain Text indexes correlate with formatted text indexes.
4.2 Arrays Issue
When a document contains an array, Ranges are bad positionned a few characters : Plain Text indexes correlate not exactly with formatted text indexes.
I found the reason of this issue (It was explained in others forums) : this is due to non printing char(7), which is a cell delimiter added in plain text. We can handle these chars to calculate position range and everything is OK !
4.3 Issue for Content Controls, Table of contents, Sections and others
When a document contains theses elements, Ranges are also bad positionned a few characters.
Others non printing appears in plain text but I don't understand what it means and how deal with to calculate position range.
By displaying Word element markers with "Developer ribbon > creation mode", we see 2 markers per elements : shifting plain text indexes by 2*elements resolve issues. It's seems OK.
4.4 Issue with Endpaper
I don't know how we says "page de garde" (french) in english, I think it's "endpaper" : this is the first page with specific header, footer and content controls :)
When a document contains an Endpaper, Ranges are also bad positionned a few characters.
But this time, there are not non printing marker in the plain text.
Other info, when I display word element markers with "Developer ribbon > creation mode", I see endpaper markers.
Questions
How detect Endpaper in Word Document Range ?
How understand Plain Text indexes don't always correlate with formatted text indexes, in function of Word document elements which contains ?
XML nodes manipulation would be a more reliable alternative for that? If yes, could you give me good examples to manage bookmars or others in current document with XML Api ?
Others ressources
I found similar issues :
Correlate Range.Text to Range.Start and Range.End
http://www.vbaexpress.com/forum/showthread.php?36710-Strange-character-on-table-range-text
I hope my explanations are clear and you can help me to understand what is wrong or show me a best way to do that ?
Thanks, really.
It's not really pretty but you can try to remove the unwanted characters by Regex. For example to remove the \a letters (it has code 7):
string j = new string(new char[] { (char)7 });
plainText = Regex.Replace(plainText,string.Format("[{0}]", j), "");
Now you have to identify the other 'evil' characters and add them to the char array. If it works you will get a string whose length corresponds with the number of Characters in your document. Probably you have to adapt this code by experimenting. (I was not sure which language you are using - I supposed C#.)
Update
Another idea (if it is applicable to your analyzer tool):
Break your problem down to single paragraphs:
foreach(Word.Paragraph pg in activeDocument.Paragraphs)
{
Word.Range range = pg.Range();
string text = range.Text;
// your stuff here
}
With this paragraph range objects and the contained text strings you do the same as you tried to do with the whole document object and its text - just paragraph by paragraph. All these paragraphs are 'addressable' by ranges and Move operations as you already do it. I suppose that the problematic characters are outside or at the end of the paragraphs so they don't influence the character counting inside these paragraphs.
As I can't reproduce what you call endpaper I can't validate it. Besides I don't know if special text ranges as page headers and tables of content are covered by paragraphs. But at least you can reduce your problem to smaller ranges. I think it is worth trying.