bryant00 / xlsb_to_csv

0 stars 1 forks source link

broken r code #1

Open mattpatton4 opened 4 years ago

mattpatton4 commented 4 years ago

rm(list=ls()) unlink(".RData") library(xlsx) library(RODBC) library(RCurl) library(XLConnect)

Folder <- "N:\RFPs\RFP 2017 Wyoming Wind\Bid Evaluations\Final Shortlist 21% Fed Tax\" Directories <- list.dirs(path = Folder, full.names = TRUE, recursive = FALSE) Output <- paste("N:\RFPs\RFP 2017 Wyoming Wind\Bid Evaluations\Final Shortlist 21% Fed Tax\TaxAdjWindBidsSummary",format(Sys.Date(),"%Y%m%d"),".xlsx",sep='') colname <- "Description"
for (i in 1:1:length(Directories)) { LFs <- list.files(Directories[i], pattern="WY|UT|WA&.xlsm") #pattern would be ignored LF <- LFs[grep(".xlsm",LFs)] #now just ".xlsb"

   if (length(LF) > 0)
   {
           for (j in 1:1:length(LF))
           {
                FileName                <-    paste(Directories[i],LF[j],sep='\\')   
                conn                    <-    odbcConnectExcel2007(FileName); #this fails
                dataframe               <-    sqlQuery(conn, "select * from [ResultsSummary$]")         #not sure why it called SQL, whoever wrote it i think knew it better
                colnames(dataframe)     <-    c(paste("X1",i,j,sep=''),substr(LF[j],1,4))   
                colname                 <-    c(colname,as.character(substr(LF[j],1,4)))                    
                if  (i == 1 && j == 1)
                {
                     Combined  <- dataframe
                }    else    {
                     Combined  <- cbind(Combined, dataframe[,2])
                }    
                close(conn)             
           } 
     }   

} Combined <- sapply(Combined, as.character) Combined[is.na(Combined)] <- " " colnames(Combined) <- colname write.xlsx(Combined,Output,sheetName="Summary",row.names=FALSE,col.names=TRUE) close(db)

mattpatton4 commented 4 years ago

output file = ResultsSummary_v1.xlsx

mattpatton4 commented 4 years ago

Copy of BTA+Battery v13_Borah3.zip ResultsSummary_v1.xlsx "Z:\RFPs\RFP 2020AS\Bid Evaluations\Initial Screening"

mattpatton4 commented 4 years ago

Here is the pshell code, slightly modified and resulting txt file. models.txt

Get-ChildItem -Path "Z:\RFPs\RFP 2020AS\Bid Evaluations\Initial Screening" -Recurse -Include .xlsb -name >>models.txt