salesforce上上传和导出.csv格式文件

1.导出.csv格式文件:其中会遇到中文乱码问题,会直接生成book.csv文件


    Name
    
        {!a.book.name}
    

  BookController如下:

public class BookController {

    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                [SELECT name FROM Book1__c]));
                //setCon.setPageSize(5);
            }
            return setCon;
        }
        set;
    }
    public List getBooks() {
        return (List) setCon.getRecords();
    }
    public List getBookWithIndex() {
        List bookList = this.getBooks();
        List bookWrapped = new List();
        Integer idex = 1;
        for (Book1__c book : bookList) {
            bookWrapped.add(new BookWrapper(book, idex));
            idex++;
        }
        return bookWrapped;
    }
    public class BookWrapper {
        public Book1__c book { get; set; }
        public Integer tabIndex { get; set; }
        public BookWrapper(Book1__c book, Integer tabIndex) {
            this.book = book;
            this.tabIndex = tabIndex;
        }
    }
}

2.上传.csv格式文件,代码如下:


    
        
        
             
                  
                  
            
        
        
           
              
        
     
   

  importDataFromCSVController代码如下:

public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvAsString{get;set;}
public String[] csvFileLines{get;set;}
public List acclist{get;set;}
  public importDataFromCSVController(){
    csvFileLines = new String[]{};
    acclist = New List(); 
  }
  
  public void importCSVFile(){
       try{
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.split('\n'); 
            
           for(Integer i=1;i

  

 

转载于:https://www.cnblogs.com/Aaronqcd/p/4514477.html

你可能感兴趣的:(数据库)