Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to remove a certain Table (xlsx-File) from some MXD-Files using python, but I can't finguring out how.

I tried the code sniplet for removing:

import arcpy, os
from arcpy import env

arcpy.env.workspace = 'V:/Projects/ZEL'

mxd =arcpy.mapping.MapDocument('V:/Projects/ZEL/test04.mxd')

df=arcpy.mapping.ListDataFrames(mxd, 'u')[0]

for lyr in arcpy.mapping.ListLayers(mxd, '', df):
    if lyr.name.lower()=='header_vorlage$':
        if lyr.dataSource == 'V:\Projects\ZEL\SHP\Daten_111004\ZEL_LB_Tabelle_V3_2010_2030.xlsx':
            arcpy.mapping.RemoveLayer(df, lyr)


mxd.saveACopy('pt.mxd')

print 'fertig'

del mxd

It works, but when I open the new created 'pt.mxd' there is still the symbol of the xlsx-Table with an '!' and you have the option to fix the datasource, because I have removed the path, but not the table...

I hope its not too confusing :)

My question is: Is there a way to remove a xlsx-Sheet from MXD-File without opening?

share|improve this question

1 Answer 1

You have used forward the forward slash in all your path references except this one 'V:\Projects\ZEL\SHP\Daten_111004\ZEL_LB_Tabelle_V3_2010_2030.xlsx' try fixing that line and see if it works.

share|improve this answer
    
Or just stick an r in front of the opening quote so it's considered a raw string. –  blah238 Oct 23 '11 at 19:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.