Jump to content

Recommended Posts

Posted

Hello,

I would like to copy a list view and past it ( to word or outlook) so it is pasted as a table - the same way it is presented in the control.

 

  • Moderators
Posted

Moved to the appropriate forum, as the AutoIt Example Scripts forum very clearly states:

Quote

Share your cool AutoIt scripts, UDFs and applications with others.


Do not post general support questions here, instead use the AutoIt Help and Support forums.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted
Posted

I start with creating a list vew as follows:

    $idListview = GUICtrlCreateListView("", 2, 2, 394, 268)
    GUISetState(@SW_SHOW)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Items", 100)

    ; Add items
    _GUICtrlListView_AddItem($idListview, "Item 1")
    _GUICtrlListView_AddItem($idListview, "Item 2")
    _GUICtrlListView_AddItem($idListview, "Item 3")........

....

....

 

Then, after the list view has values, I would like to copy its data and paste it (to Word Document) so the data will show also as a table (like a table created by Word).

Is it possible?

 

Posted
3 hours ago, Nine said:

easiest approach is to parse your entire List View into a 2D array and use Word UDF _Word_DocTableWrite function to write it at once into a document

Yep, something like this:

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <Word.au3>

Global $sFile = @DesktopDir & '\Test.doc'

$hGUI = GUICreate('Test', 240, 300)

$iLV = GUICtrlCreateListView('Col1|Col2|Col3', 20, 20, 200, 240)

For $i = 1 To 10
    GUICtrlCreateListViewItem('Item' & $i & '|SubItem 1|SubItem 2', $iLV)
Next

$iCopy_Bttn = GUICtrlCreateButton('Copy to word', 20, 270, 80, 20)
$iStatus_Lbl = GUICtrlCreateLabel('', 110, 273, 100, 15)
GUICtrlSetColor(-1, 0xFF0000)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iCopy_Bttn
            Local $iCount = _GUICtrlListView_GetItemCount($iLV)
            Dim $aTable[$iCount][3] = [[$iCount]]
            
            For $i = 0 To $iCount - 1
                For $j = 0 To 2
                    $aTable[$i][$j] = _GUICtrlListView_GetItemText($iLV, $i, $j)
                Next
            Next
            
            GUICtrlSetData($iStatus_Lbl, 'Please wait...')
            FileClose(FileOpen($sFile, 2)) ;2 - Rewrite, use 1 to append
            
            Local $oWord = _Word_Create(False, True)
            Local $oDoc = _Word_DocOpen($oWord, $sFile)
            Local $oRange = _Word_DocRangeSet($oDoc, -2)
            
            _Word_DocTableWrite($oRange, $aTable, 0)
            _Word_DocClose($oDoc, $WdSaveChanges)
            _Word_Quit($oWord)
            
            GUICtrlSetData($iStatus_Lbl, '')
    EndSwitch
WEnd

But still it's also interesting for me to find a way to actually put the table to the clipboard (as RTF format for example) without using external tools.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...