Hi,

I have been trying to use multiple command i can find online to spilt the columns into different files but couldnt.

I have an 10 columns excel file ( first 2 col is paramaters, the remaining 8 col is the data). I would like to split it into 8 separate files which all 8 contains first 2 col paramaters and 1 data col. 

May i know does anyone have any idea to get around this ? 

Thank you.
Here is the code in R: Make sure that all for the files (excel files with .xls or .xlsx) are in the same format as in link furnished above (2nd column is mz, 5 is RT and 11th column onward samples). Code would create one excel file per sample and name of the excel file would be sample_"sample name".xls. It will have three columns: mz, RT and sample name.

    library(readxl)
    library(WriteXLS)
    df=data.frame(read_xls("example.xls"))
    
    for (i in 11:ncol(df)){
        temp_df=df[,c(2,5,i)]
        WriteXLS(temp_df, ExcelFileName = paste0("sample_",names(df)[i],".xls"))
    }

if you have multiple xls files in the folder (and only xls files of interest):

    setwd("~/Desktop/test") # change this to directory of interest
    fn=list.files(pattern = "\\.xls") # lists files with .xls extension
    library(readxl)
    library(WriteXLS)
    
    for (i in fn){
        df=data.frame(read_xls(i))
        for (j in 11:ncol(df)){
            temp_df=df[,c(2,5,j)]
            WriteXLS(temp_df, ExcelFileName = paste0(sub('\\.xls$', '', i) ,"_","sample_",names(df)[j],".xls"))
        }
        }

output files will have "xlsfilename_samplename.xls"