Problème de modification du type d'une colonne d'un fichier source Excel

Résolu/Fermé
developpeir2019 Messages postés 7 Date d'inscription jeudi 16 mai 2019 Statut Membre Dernière intervention 22 mai 2019 - 16 mai 2019 à 19:16
developpeir2019 Messages postés 7 Date d'inscription jeudi 16 mai 2019 Statut Membre Dernière intervention 22 mai 2019 - 22 mai 2019 à 12:02
Bonjour,


Je travaille avec un fichier excel de 30 000 enregistrements que je dois intégrer avec SSIS. Ce fichier contient des colonnes de type alphanumérique.
Pour éviter que ces colonnes ne soient entrées avec la valeur NULL, j'ai crée la tâche script qui modifie le type des colonnes depuis la source Excel de "Standard" à "Texte"


c_colonne = m_XlWrkSheet.Cells.Find("colonnealphanum", LookIn:=Excel.XlFindLookIn.xlValues)
If Not c_colonne Is Nothing Then
m_XlWrkSheet.Columns(c_colonne.Column).NumberFormat = "@"
End If


Le problème est que cette solution ne marche pas avec toutes les colonnes; il y a des colonnes dont le type est modifié, d'autres NON!!! et j'ignore les causes!!

SVP , au secours, je galère depuis une semaine!
A voir également:

1 réponse

yg_be Messages postés 22707 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 19 avril 2024 1 471
19 mai 2019 à 13:03
bonjour, il me semble que ton code ne traite intentionnellement qu'une seule colonne.
1
developpeir2019 Messages postés 7 Date d'inscription jeudi 16 mai 2019 Statut Membre Dernière intervention 22 mai 2019
19 mai 2019 à 13:09
Non non.. J'ai effectué ce traitement pour toutes les colonnes.. C'est juste que j'ai partagé uniquement un exemple du script
0
yg_be Messages postés 22707 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 19 avril 2024 1 471 > developpeir2019 Messages postés 7 Date d'inscription jeudi 16 mai 2019 Statut Membre Dernière intervention 22 mai 2019
19 mai 2019 à 13:20
il faudra alors que tu nous donnes plus d'information.
0
developpeir2019 Messages postés 7 Date d'inscription jeudi 16 mai 2019 Statut Membre Dernière intervention 22 mai 2019
Modifié le 20 mai 2019 à 12:04
Voici le code du script:


#Region "Help: Introduction to the script task"
'The Script Task allows you to perform virtually any operation that can be accomplished in
'a .Net application within the context of an Integration Services control flow.
'Expand the other regions which have "Help" prefixes for examples of specific ways to use
'Integration Services features within this script task.
#End Region
#Region "Imports"
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.Office.Interop
#End Region
'ScriptMain is the entry point class of the script. Do not change the name, attributes,
'or parent of this class.
<Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute()> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Public Sub Main()
Dim m_XlApp As New Excel.Application
Dim m_xlWrkbs As Excel.Workbooks = m_XlApp.Workbooks
Dim m_xlWrkb As Excel.Workbook
m_xlWrkb = m_xlWrkbs.Open(Convert.ToString(Dts.Variables("User::ExcelPath").Value))
Dim m_XlWrkSheet As Excel.Worksheet = m_xlWrkb.Worksheets(1)



Dim c_bureau As Excel.Range
Dim c_situation As Excel.Range


With m_XlWrkSheet
c_bureau = m_XlWrkSheet.Cells.Find("bureau", LookIn:=Excel.XlFindLookIn.xlValues)
c_situation = m_XlWrkSheet.Cells.Find("situation", LookIn:=Excel.XlFindLookIn.xlValues)

If Not c_bureau Is Nothing Then
m_XlWrkSheet.Columns(c_bureau.Column).NumberFormat = "@"
MsgBox("hello1")
m_xlWrkb.Save()
End If

If Not c_situation Is Nothing Then
m_XlWrkSheet.Columns(c_situation.Column).NumberFormat = "@"
MsgBox("hello2")
m_xlWrkb.Save()
End If

m_xlWrkb.Close(SaveChanges:=True)
End With
Dts.TaskResult = ScriptResults.Success
End Sub
#Region "ScriptResults declaration"
'This enum provides a convenient shorthand within the scope of this class for setting the
'result of the script.
'This code was generated automatically.
Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum
#End Region
End Class

Ça marche pour bureau et pas pour situation.D'autant que les deux messages "hello1" et "hello2" s'affichent.
0
yg_be Messages postés 22707 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 19 avril 2024 1 471
20 mai 2019 à 14:40
"Ça marche pour bureau et pas pour situation": tu veux dire que le format de situation n'est pas changé, ou bien que ce changement ne produit pas l'effet souhaité?
0
developpeir2019 Messages postés 7 Date d'inscription jeudi 16 mai 2019 Statut Membre Dernière intervention 22 mai 2019
20 mai 2019 à 16:54
Le format n'est pas changé à 'Texte'
0