w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Python RE Find a Specific Word In a Text Document
You're getting an AttributeError: 'NoneType' object has no attribute 'group' because the match has not been found. re.search() will return None if there is no match, so you can do this: import re with open('text.txt', 'r') as myfile: for line in myfile: m = re.search('(.*)(?<=Dog)Food(.*)', line) if m is not None: m.group(0) print "Found it." break # Break out of the loop Edit: I've edited my answer with your code. Also, I've used with/as here, as it automatically closes the file afterwards (and it looks pretty cool :p)

Categories : Python

How to read font size of each word in a word document using POI?
Yes, that's the correct way; the measurement is in half points. In a docx, you'd have something like: <w:rPr> <w:sz w:val="28" /> </w:rPr> ECMA 376 spec on @sz defines the unit as ST_HpsMeasure (Measurement in Half-Points) Its the same with the binary doc format, which HWPF supports. If you look at [MS-DOC], you'll see it also specifies the size of text in half-points.

Categories : Java

Replacing one specific word in the textarea
As mentioned in my comment, you could replace the very last word, that is most probably the one you're currently typing. Or you can take a look here and see how to get the current cursor position. You'll have the exact word to replace afterwards.

Categories : Javascript

use excel 2010 vba to create a word document that consists text from multiple word files
As KazJaw said above, as an intermediate VBA user you should be able to create the userform and related code that allows your users to select the Word document as you describe. Once you get to working with the Word document things get a bit different from coding for Excel. Let me share the little I know about this: First, make sure you've activated the Word Object Library: on the Tools menu, click References. In the list of available references, find and select the appropriate Microsoft Word Object Library As I understand it, late binding just means declaring the object type when you assign the value. I have no idea if this will solve your 'Error Accessing the System Registry' issue. I have used late binding when I call Word Documents by first defining a variable as a generic object: D

Categories : Excel

Apache POI Word .DOC Replacing Text
This presents the alternatives. It is in the context of docx4j, but the options also apply in principle to POI.

Categories : Apache

replacing occurences of a word with another on the first line of a text in PHP
You can load only first line to variable, than do str_ireplace and then put first line + rest of the file back together. $data = explode(" ", $string); $data[0] = str_ireplace("%title%", "TITLE", $data[0]); $string = implode(" ", $data); Its not the most efficient way imho, but suitable and fast to code.

Categories : PHP

linux wine Word interop application.Documents.Open opens a document in word but does not return the document to the client
This is a known bug in Wine. You can read more here: http://osdir.com/ml/wine-bugs/2013-07/msg01794.html

Categories : C#

How to parse text from MS Word document to string
You could give a look at NPOI: This project is the .NET version of POI Java project at http://poi.apache.org/. POI is an open source project which can help you read/write xls, doc, ppt files. It has a wide application. Take a look at this previous SO thread for more information.

Categories : C#

How to iterate through text in the Word document by VB macro
Using VBA, to count the number of characters in the active document do: ActiveDocument.Range.ComputeStatistics(wdStatisticCharacters) or Activedocument.Range.Characters.Count To get the count for the current selection: Selection.Range.ComputeStatistics(wdStatisticCharacters) or Selection.Range.Characters.Count The second method in each example counts spaces as characters, the first doesn't. EDIT: I did some speed testing on various methods to count the instances of a char in a document. Regular expressions and stuffing the document contents into a string are fastest - many times faster than looping through each character or FIND For my test document I copied the contents of this web page into a Word document. As an accuracy check, I used Word's Find function/panel to find th

Categories : Vba

Javascript / REGEX: Delete a specific Text (word) starting with a specific letter inside a String with words separated by spaces
How about: str.replace(/sS+/ig,"") Explanation: NODE EXPLANATION ----------------------------------------------------------------------  the boundary between a word char (w) and something that is not a word char ---------------------------------------------------------------------- s 's' ---------------------------------------------------------------------- S+ non-whitespace (all but , , , f, and " ") (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- i is for case-insensitive g is for global

Categories : Javascript

How do I search a txt document for a word and write that word to a new document for reporting?
Something like: foreach(var line in File.ReadLines(filename) .Where(l => l.Contains("ERROR MESSAGE"))) { // Log line } Additionally if you need specific information inside the line you can use a Regex to capture the information. I cannot provide a better example without more information.

Categories : C#

Javascript: find all occurrences of word in text document
I don't know what is going on there but I can offer a better solution using a regex. function getMatches(haystack, needle) { var regex = new RegExp(needle.toLowerCase(), 'g'), result = []; haystack = haystack.toLowerCase(); while ((match = regex.exec(haystack)) != null) { result.push(match.index); } return result; } Usage: getMatches('hello hi hello hi hi hi hello hi hello john hi hi', 'hi'); Result => [6, 15, 18, 21, 30, 44, 47] Conserning your book vs books problem, you just need to provide "book " with a space. Or in the function you could do. needle = ' ' + needle + ' ';

Categories : Javascript

Visual basic text fields data to MS Word document
To get your code to work You would need to index the Fields collection To index the Fields COllection you have to use a number (a Long), not a text value But to do that, you have to know what number to use. But what type of field are you trying to replace? Is it a REF field? If it is your choice and you need to use fields, you may be better off using { DOCVARIABLE } fields and setting the values of the corresponding Variables. Or, if you only need to support Windows Word 2007 and later, it might be better to use Content Controls linked to custom XML.

Categories : Vb.Net

How to write rich text to word document generated from htm file in C#
Actually the converting of HTML document to MS Word is a very complex task and there are a lot of cases besides of IMAGE tags which need to be solved. The difference between Open XML and HTML formats is absolutely decisive. If I were you I would look for 3rd party tools for that. It would be chiper to pay for them than spending weeks on investigation and learning of all aspects of the task, writing the code, and then fixing miltiple bugs. Personaly me used Aspose.Words library for that. It worked perfectly fine, but maybe you want to try another one.

Categories : C#

powershell - MS-Word document parsing - Get a table's caption text
Captions aren't properties of table objects, they're just text. You could do something like this for finding table captions, though: $style = $doc.Styles | ? { $_.NameLocal -eq 'Caption' } $wd.Selection.Find.Style = $style $wd.Selection.Find.Text = 'Table' # if table captions are labeled "Table" $wd.Selection.Find.Execute() Since wildcard matches are non-greedy in Word, you may have to do something like this: $style = $doc.Styles | ? { $_.NameLocal -eq 'Caption' } $wd.Selection.Find.Style = $style $wd.Selection.Find.Wrap = 0 while ($wd.Selection.Find.Execute()) { if ($wd.Selection.Text -like 'Table*') { # do stuff } $wd.Selection.MoveRight() } The above matches just by style, so it should select the entire caption. The MoveRight() unselects the caption afterwards, so the

Categories : Powershell

Replace Images in Word Document with string/text placeholder
Two possible solutions which will work with InlineShapes only (according to comments that could be ok.) Solution 1 constant replacement text: Sub ReplaceInlineShapes_constant_names() Dim oILShp As InlineShape For Each oILShp In ActiveDocument.InlineShapes 'insert text in place where InlineShape is located ActiveDocument.Range(oILShp.Range.Start, oILShp.Range.End).Text = "[Image.Jpg]" 'delete picture is not needed- it was simply replaced with text Next End Sub Solution 2 replacement text with index within: Sub ReplaceInlineShapes_WithIndex() Dim oILShp As InlineShape Dim ILShpIndex As Integer For Each oILShp In ActiveDocument.InlineShapes ILShpIndex = ILShpIndex + 1 'insert text in place where InlineShape is located ActiveDocument.Range(oILShp.Range.Start,

Categories : Image

How to convert a word document to a text file in c# without using microsoft.office.interop?
Finally I found solution which perfectly works for me at the moment. I haven't test with 10000 documents. Here you go., http://sourceforge.net/projects/word-reader/?source=dlp Comments and suggestions are expecting about this solution... Thank you, Shanthini

Categories : C#

How can i generate a word document docx with existing text as in a template, but fill in value thru a asp.net web form?
You have several options for creating word documents - Use word automation - this is using Ms Word directly. Not recommended if you're running on a server - it's slow and suffers from extensibility and other issues. Use OpenXML - this is Microsoft's SDK to work with Office 2007+ file formats. There are several ways to accomplish your goal with OpenXML - like using bookmarks or content controls. Look at this SO question - How to replace content in template docx document and Open XML SDK 2.0 (Aug 09)? or this one - How to create *.docx files from a template in C# or google it (while not that difficult, the entire solution is more that a few lines of code and does require a bit of understanding) Use third party tools or controls - I'm not really familiar with them.

Categories : C#

Javascript, Firefox replacing entire document without document.write
I would recommend you to make use of the .html() function of jQuery. (or innerHTML if you prefer to make use of pure Javascript) If the document DOM has already been loaded you shouldn't be using document.write.

Categories : Javascript

If text in a cell contains a specific word then put an image in it
var allTableCells = document.getElementsByTagName("td"); var yourImage = new Image(); yourImage.src = "HW.png"; for (var i = 0;i < allTableCells.length; i++) { var node = allTableCells[i]; if (node.textContent.trim() === "ArmHW") { node.textContent = ""; node.appendChild(yourImage); } }

Categories : Javascript

how to get a range to text near a specific word in a NSString?
This will do it: - (NSString *)getSnippetContaining:(NSString *)keyword inString:(NSString *)theString numberOfWords:(NSUInteger)wordCount { NSRange range = [theString rangeOfString:keyword options:NSBackwardsSearch range:NSMakeRange(0, theString.length)]; if (range.location == NSNotFound) { return nil; } NSString *substring = [theString substringFromIndex:range.location]; NSArray *words = [substring componentsSeparatedByString:@" "]; if (wordCount > words.count) { wordCount = words.count; } NSArray *snippetWords = [words subarrayWithRange:NSMakeRange(0, wordCount)]; NSString *snippet = [snippetWords componentsJoinedBy

Categories : Objective C

How to change the text color of specific word of textview in ios5
Support for attributed strings in UIKit classes like UITextView was only added in iOS 6. To do this on earlier systems you will have to draw the strings yourself using Core Text or a framework like DTCoreText.

Categories : IOS

How to replace a character in some specific word in a text file using python
You can probably get away with matching just a leading digit followed by O. This won't handle OO7, but it will work nicely with 8080 for example. Which none of the answers here matching the trailing digits will. If you want to do that you need to use a lookahead match. re.sub(r'(d)(O+)', lambda m: m.groups()[0] + '0'*len(m.groups()[1]), content)

Categories : Python

How can I change the color of a specific word(or phrase) in the Text content of a RichTextBox
Did you see this link Answer here Check it: Change color and font for some part of text in WPF C#

Categories : C#

Convert PDF document to Word document by programmatically without any third party tool (SSRS 2005)
There are many fundamental differences between PDF and Word making the approach you want highly undesirable as a general workflow. I'll give just one example: PDF typically does not store information about document structure - sentences, paragraphs, columns, tables... All it stores is the actual text at certain locations at a page. Word of course does have those concepts. Is it possible to do what you want? Yes, to some extent. In the general case with guesswork and approximation. If you know which information you want to convert it might be possible to search for it in the PDF file generated by SSRS and then generate a Word file out of it. However, if SSRS allows export to text, XML, RTF or any other structure based file format (however slightly structure based), you'd have a much easier

Categories : C#

Replace A string token in Word document with a word table
Try this: protected void InsertTableAtBookMark(string[][] docEnds, string bookmarkName) { Object oBookMarkName = bookmarkName; Range wRng = WordDoc.Bookmarks.get_Item(ref oBookMarkName).Range; Table wTable = WordDoc.Tables.Add(wRng, docEnds.Length, docEnds[0].Length); wTable.set_Style("Table Grid"); for (int i = 0; i < docEnds.Length; i++) { for (int j = 0; j < docEnds[0].Length; j++) { wTable.Cell(i, j).Range.Text = docEnds[i][j]; wTable.Cell(1, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft; wTable.Cell(1, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter; } } Borders wb = wT

Categories : Dotnet

How can I use javascript to check if a sharepoint textfield contains a specific word, when the textbox text changes or get added?
.change() wont fire on content editable div's, try using blur() $(".ms-taxonomy .ms-taxonomy-fieldeditor").blur(function () { var Text = $(this).text(); if (Text == "Hello World") { // do this } }); You can also reference ASP.NET controls via ID (if your JS is in the same file) by using this format: $("#<%= EditModePanel5Medium.ClientID %>")

Categories : Javascript

PHP - Get a word count from an uploaded Microsoft Word document
You will need to: Distinguish the file type $file_name = $_FILES['image']['name']; $file_extn = end(explode(".", strtolower($_FILES['image']['name']))); if($file_extn == "doc" || $file_extn == "docx"){ docx2text(); }elseif($file_extn == "rtf"){ rtf2text(); } Convert the document to text http://stackoverflow.com/a/7371315/2512934 for doc or docx http://webcheatsheet.com/php/reading_the_clean_text_from_rtf.php for rtf Count the words http://php.net/manual/en/function.str-word-count.php

Categories : PHP

iOS: referring to a specific font within a font family?
So your fonts just aren't working? You almost guaranteed have the wrong name (if you've already added it to the plist). Check your font name: for (NSString *name in [UIFont familyNames]) { NSLog(@"Family name : %@", name); for (NSString *font in [UIFont fontNamesForFamilyName:name]) { NSLog(@"Font name : %@", font); } } However I'd also check out this answer: Font not loading in XCode The .otf may be the problem.

Categories : IOS

Check if a string starts with the a specific word, if True then print word - PYTHON
You can use str.startswith(): for word in SideMember: if word.startswith('Base'): print word It does exactly as you would expect it to do ;). By the way, you should only use capitalised variable names for classes. Some other methods you probably shouldn't consider, but for the fun of it I included them :p import re for word in sidemembers: if re.search(r'^Base', word) is not None: print word for word in sidemembers: if word[:4] == 'Base': print word

Categories : Python

how to Create table in word doc using docx4j in specific bookmark without overwritting the word doc
You can adapt the sample code BookmarksReplaceWithText.java In your case: line 89: the parent won't be p, it'll be body or tc. You could remove the test. line 128: instead of adding a run, you want to insert a table You can use TblFactory to create your table, or the docx4j webapp to generate code from a sample docx.

Categories : Java

Replacing all occurrences of a word with another
You don't need regex here, and neither Pattern and Matcher classes. Simple use of String.replace() will work fine: input = input.replace("japan", "Japan");

Categories : Java

Python string, find specific word, then copy the word after it
It's not the most efficient code in the world, but it is still probably better than a regex: tokens = teststring.split() numlist = [val for key, val in zip(tokens, tokens[1:]) if key == 'number:'] for your follow-up and more general queries: def find_next_tokens(teststring, test): tokens = teststring.split() return [val for key, val in zip(tokens, tokens[1:]) if test(key)] Which could be called as: find_next_tokens(teststring, lambda s: s.startswith('number') and s.endswith(':')) This will help if the keys to search for come from user input: find_next_tokens(teststring, lambda s: s in valid_keys)

Categories : Python

multipule text font size for font in one text box
Use a richtextbox instead. richTextBox1.SelectionFont = new Font("Arial", 12, FontStyle.Bold); richTextBox1.AppendText("Two of the peak human experiences are"); richTextBox1.SelectionFont = new Font("Tahoma", 16, FontStyle.Bold); richTextBox1.AppendText("good food and classical music");

Categories : Wpf

CSS3 @font-face causes the font file to output its sample text
I'm also tested with the SteelTongs web font in firefox and chrome, it is not supported,the font link is abstractfonts- steeltongs ,U just change the font.

Categories : CSS

How to preserve text formatting in RichTextBox like Bold, Italics, font color, font size, etc?
RichTextBox supports rtf content, you can't past directly Word content in your RichTextBox. You need to convert the word document into .rtf file. Best way is to use the save As dialog in Microsoft Word. Then you could deploy the document with your application and then load rtf content in your RichTextBox using LoadFile method. RichTextBox1.LoadFile("Help-File.rtf") Obviously, it supposes that basic formatting like mentioned in title (Bold, Italics, font color, font size, ...) are enough for this purpose, since the rft format does not support obviously all MS Word features. Otherwise you may have to implement your own parse/interpretation logic.

Categories : Vb.Net

Replacing comma with & before the last word in string
Here's my take on this, using array_pop(): $str = "A, B, C, D, E"; $components = explode(", ", $str); if (count($components) <= 1) { //If there's only one word, and no commas or whatever. echo $str; die(); //You don't have to *die* here, just stop the rest of the following from executing. } $last = array_pop($components); //This will remove the last element from the array, then put it in the $last variable. echo implode(", ", $components) . " &amp; " . $last;

Categories : PHP

replacing strings in a document and undo
Serge, I've been working on the very same problem! I've got a partial workaround to share, and some ideas to take it further. There is no way to embed hidden text in Google Docs, as eloquently stated by Gill on the old forum. If there was, your mailmerge would be trivial! How about making your tags or "cookies" (almost) invisible, though? Below is a scriplet that adds a "cloaking" function to a document. It has extras as well; it queries the user for text to cloak, then searches for all instances of that text and cloaks them. The idea I settled on was to make the text as small as possible (fontsize 0) and to match the foreground color to the background color. // in menu: .addItem('Text Cloaking', 'cloakOn') /** * Find all matches of target text in current document, and cloak the

Categories : Google Apps Script

replacing one word by another in an entire directory - unix
You probably have perl installed (if its UNIX), so here's something that should work for you: perl -e "s/Foo/Bar/g;" -pi.save $(find path/to/DIRECTORY -type f) Note, this provides a backup of the original file, if you need that as a bit of insurance. Otherwise, you can do what @Kevin mentioned and just use an IDE refactoring feature. Note: I just saw you're using Vim, here's a quick tutorial on how to do it

Categories : Regex

Update data in document without replacing values
Use the . userData = { "profile.firstName": 'Hello', "profile.lastName": 'Kora', "profile.phoneNumber": '0422222222' }; These will ensure only those particular keys are altered.

Categories : Mongodb



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.