Friday, August 24, 2018

How to get word document headings to into excel

I'm trying to import the headings of word document to an excel spreadsheet.

Word Headings:

1 Heading 1

1.1 Heading 2

1.1.1 Heading 3

The spreadsheet would have columns Heading 1, Heading 2, Heading 3

Table example

Solved

I'm sorry there was a big mistake in my first answer. You don't need the application object to create your word app.

The correct code see below:

Option Explicit

Public Sub Test_ReadWordDocument()
    Dim WordApp     As Object
    Dim WordDoc     As Object
    Dim Para        As Object

    Set WordApp = CreateObject("Word.Application")
    Set WordDoc = WordApp.Documents.Open("...\TestReadWordDoc.docx")

    For Each Para In WordDoc.Paragraphs
        Debug.Print Para.Range.Text
    Next Para

End Sub

Result:

Heading1
Heading2
Heading3
Lore ipsum Lore ipsum 
Lore ipsum 
Lore ipsum 
Lore ipsum

From there you can go on. Use the locals window to inspect the late binded objects. :)


Monday, August 20, 2018

ERP: Is there a design pattern for updating data for a department while keeping the old data for a second department during a certain time?

Not so complicated as the title suggests. Imagine two departments in a Company: Sales and Manufacture. While data (in an ERP software) in Sales may represent contracts, Manufacture has to deal with the production established by these contracts (ex: produce 1,000 pens/month). The challenge here is that Sales should be able to update a contract in any business hour but must not mess up with production until the end of the day. In other words, for Manufacture the contract data should appear as the old one, before update. For Sales, the contract must appear as the new updated one. Manufacture should "see" the update only in the next day.

This is a Java ERP application. How to deal with this kind of situation using a best practice or design pattern?

Solved

This sounds like a model-view-controller pattern to me. I think it would be best if you made a class to store the actual data, and it serves that data to the Sales and Manufacture classes.

What you would do then is whenever the Sales class wants to update a contract, it is internally labeled with the business hour it was posted. Then, whenever the Manufacture class wants to get contract information, anything that was posted within that business day is ignored, and not returned.

How you want to do this is pretty much up to you. TheBetaProgrammer's idea works nicely, but is complicated by how you want different visibility for different departments. You might want to make a class that stores the contract and visibility permissions, and when data is requested, check if the requester is allowed to see that version of the contract before returning it.


Sunday, August 19, 2018

Using expect to run "nc -w 3 -z $IP 22" command on macOS but get long waiting timeout

I using linux expect command to execute "nc -w 3 -z $IP 22" command on macOS.

I expected timeout after 3 seconds but I got 1m 15s (Due to "nc" command can setting timeout via "-w" argument).

I run the same code at other linux(Debian 7.8, ubuntu 14.04) machines are normally.

Who can tell me why I got the different result between linux and macOS ?

Following content is my source code:

#!/usr/bin/expect -f

set DUT_IP "192.168.1.2"

if {0!=[catch {exec sh -c "nc -w 3 -z $DUT_IP 22 && echo \$?"}]} {
  send_user "Cannot connect to DUT $DUT_IP\n"
  exit -1
} else {
  puts "IP exist"
}

Saturday, August 18, 2018

exponential notation to integer notation XSLT2.0

IS it possible to change the following exponential notation to integer notation using XSLT 2.0.

2.0151109001E10 to 20151109001

I tried with

number(2.0151109001E10)

but it gives NaN as answer.

EDIT: XSLT:




OUTPUT:

 2.0151109001E10
 2.0151109001E10
 2.0151109001E10

The following works out


Solved

The real problem with your input is not the exponential notation, but the use of a comma as the decimal mark. XML only recognizes a period as the decimal mark.

Try something like:


or:



You can try to put them inside the single quotes '' like this:

number('7.2345E7')

gives

72340000

You can use format-number:

format-number(2.0151109001E10, '#')