Jump to content

CSV-Editor V0.8


funkey
 Share

Recommended Posts

  • 6 months later...

taietel some great Functions, But (sorry about that :)) there is a potential problem with _CSV_FindDelimiter() in that if it Returns the Delimiter the File isn't closed!! So here is my attempt at the Function.

Function:

Func _CSV_FindDelimiter($sFileName)
    Local $aDelimiter = StringSplit(@TAB & "@,@;@,;@|@" & "'@" & '"', "@", 2), $aSRE
    Local $hFileOpen = FileOpen($sFileName, 0), $iIndex = 0, $iUbound = UBound($aDelimiter, 1), $sData
    If $hFileOpen = -1 Then
        Return SetError(1, 0, "")
    EndIf
    $sData = FileRead($hFileOpen)
    FileClose($hFileOpen)
    $aSRE = StringRegExp($sData, '(?s)(?i)(.*?)' & @CRLF, 3)
    If @error Then
        Return SetError(1, 0, "")
    EndIf
    If UBound($aSRE, 1) >= 2 Then
        $iIndex = 1
    EndIf
    For $A = 0 To $iUbound - 1
        If StringInStr($aSRE[0], $aDelimiter[$A]) <> 0 And StringInStr($aSRE[$iIndex], $aDelimiter[$A]) <> 0 Then
            Return $aDelimiter[$A]
        EndIf
    Next
    Return SetError(1, 0, "")
EndFunc   ;==>_CSV_FindDelimiter

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 11 months later...

funkey

WM_COMMAND - to hide the input field with a loss of focus

problem remains : if the scrolling ListView, the "Input" does not scroll.

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

Opt("GUIOnEventMode", 1)
Global $aElement[2], $hActive, $iInput
Global $iListView, $hListView, $dummy1, $dummy2

$hGUI = GUICreate('Double click on the item', 450, 360)
GUISetOnEvent(-3, '_Exit')
$iInput = GUICtrlCreateInput("", 0, 0, 0, 0)
GUICtrlSetState(-1, $GUI_HIDE)
$iListView = GUICtrlCreateListView('Col 1|Col 2', 5, 5, 440, 330, BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_REPORT, $LVS_SHOWSELALWAYS))
$hListView = GUICtrlGetHandle(-1)

For $i = 1 To 20
 $item1 = Random(10, 99, 1)
 $item2 = ''
 For $j = 1 To 9
  $item2 &= Chr(Random(97, 122, 1))
 Next
 GUICtrlCreateListViewItem($item1 & '|' & $item2, $iListView)
Next

GUICtrlCreateButton('Button', 10, 340, 70, 20)

$dummy1 = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "_Exit")
$dummy2 = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "_SaveChange")
Global $AccelKeys[2][2] = [["{ESC}", $dummy1],["{ENTER}", $dummy2]]
GUISetAccelerators($AccelKeys)
GUISetState()
GUIRegisterMsg(0x4E, "_WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ; to hide the input field with a loss of focus

While 1
 Sleep(100000)
WEnd

; Displays Input element to the fore
Func _GUICtrlListView_EditItem($hWnd, $iIndex, $iSubItem)
 ;funkey 19.02.2010
 If $iIndex < 0 Then Return
 Local $aPos, $aRect, $iSum = 0
 Local $x, $y, $w, $h
 For $i = 0 To $iSubItem - 1
  $iSum += _GUICtrlListView_GetColumnWidth($hWnd, $i)
 Next
 $aRect = _GUICtrlListView_GetItemRect($hWnd, $iIndex)
 $aPos = ControlGetPos($hGUI, "", $hWnd)
 $x = $iSum + $aPos[0] + $aRect[0]
 $y = $aPos[1] + $aRect[1]
 $w = _GUICtrlListView_GetColumnWidth($hWnd, $iSubItem)
 $h = $aRect[3] - $aRect[1]
 GUICtrlSetPos($iInput, $x - 1, $y + 1, $w + 1, $h + 1)
 GUICtrlSetData($iInput, _GUICtrlListView_GetItemText($hWnd, $iIndex, $iSubItem))
 GUICtrlSetState($iInput, $GUI_SHOW)
 GUICtrlSetState($iInput, $GUI_FOCUS)
 $aElement[0] = $iIndex
 $aElement[1] = $iSubItem
EndFunc

; Save changes to the item
Func _SaveChange()
 Local $sText = GUICtrlRead($iInput)
 If StringInStr($sText, @CR) Or StringInStr($sText, @LF) Then
  If StringLeft($sText, 1) <> '"' And StringInStr(StringMid($sText, 2, StringLen($sText) - 2), '"') Then $sText = StringReplace($sText, '"', "'")
  $sText = '"' & StringReplace($sText, '"', '') & '"'
 EndIf
 _GUICtrlListView_BeginUpdate($hActive)
 _GUICtrlListView_SetItemText($hActive, $aElement[0], $sText, $aElement[1])
 GUICtrlSetState($iInput, $GUI_HIDE)
 _GUICtrlListView_SetColumnWidth($hListView, $aElement[1], -2) ;$LVSCW_AUTOSIZE_USEHEADER
 _GUICtrlListView_EndUpdate($hActive)
 Return $sText ; return text if you want to use it
EndFunc

Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
 Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
 $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
 $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
 $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
 $iCode = DllStructGetData($tNMHDR, "Code")
 Switch $hWndFrom
  Case $hListView
   Switch $iCode
    Case $NM_DBLCLK ; Double click to edit ListView item
     Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
     _GUICtrlListView_EditItem($hListView, DllStructGetData($tInfo, "Index"), DllStructGetData($tInfo, "SubItem"))
     $hActive = $hListView
   EndSwitch
 EndSwitch
 Return $GUI_RUNDEFMSG
EndFunc

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
 #forceref $hWnd, $iMsg
 Local $iIDFrom, $iCode
 $iIDFrom = BitAND($iwParam, 0xFFFF) ; LoWord
 $iCode = BitShift($iwParam, 16) ; HiWord
 Switch $iIDFrom
  Case $iInput
   Switch $iCode
    Case $EN_KILLFOCUS
     GUICtrlSetState($iInput, $GUI_HIDE)
   EndSwitch
 EndSwitch
 Return $GUI_RUNDEFMSG
EndFunc

Func _Exit()
 Exit
EndFunc
Edited by AZJIO
Link to comment
Share on other sites

  • 6 months later...

Very good work, but the script crashed when one of the columns is very large.

It's crashed because of RegExp, here is an example:

$vTest = '"'

For $i = 1 To 5935 ;Change to 5934 and no crash
    $vTest &= '0'
Next

$vTest &= '"'

$aRet = StringRegExp($vTest, '([^"])*', 3) ;Or change the pattern to '([^"]*)'
ConsoleWrite("Result: " & $aRet[1] & @LF)

 

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

Link to comment
Share on other sites

  • 2 years later...
  • 5 months later...

I tried to create some CSV functions. All files I checked were parsed wihtout errors:

 

Edit: fixed a few errors in _ParseCSV

Hi Andy,

Thanks for the good work!

Theres a little thing in that could easily blow up the memory when working with large files. Change the last iteration in _parsecsv to this

        If $iSub = $iSubBound Then
            $iSubBound += 1
            ReDim $aResult[int($iBound/$iSubBound)+1][$iSubBound]
        EndIf

and all is good :)

Cheers.

Link to comment
Share on other sites

Changed few things to run with actial version of AutoIt.

 

Download in first post.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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