生成csv文件 可以使用excell读取




- (IBAction)btnPressed:(id)sender {

//文档地址    

    NSArray *documents =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

    NSString *docementDir = [documentsobjectAtIndex:0];

    NSString *filePath = [docementDirstringByAppendingPathComponent:@"student.csv"];

//初始化数据

    [selfformatDates];

//创建文件

    [selfcreateFile:filePath];

//导出数据

    [selfexportCSV:filePath];

}



- (void)createFile:(NSString *)fileName {

    NSFileManager *fileManager = [NSFileManagerdefaultManager];

    [fileManager removeItemAtPath:fileNameerror:nil];

    if (![fileManagercreateFileAtPath:fileNamecontents:nilattributes:nil]) {

        NSLog(@"不能创建文件");

    }

}




- (void)exportCSV:(NSString *)fileName {

    

    NSOutputStream *output = [[NSOutputStreamalloc]initToFileAtPath:fileNameappend:YES];

    [output open];

    if (![outputhasSpaceAvailable]) {

        NSLog(@"没有足够空间");

    }

    else

    {

        NSString *head =@"学号,姓名\n";

        constuint8_t *headerString = (constuint8_t *)[head cStringUsingEncoding:NSUTF8StringEncoding];

        NSInteger headerLength = [headlengthOfBytesUsingEncoding:NSUTF8StringEncoding];

        NSInteger result = [outputwrite:headerStringmaxLength:headerLength];

        if (result <=0) {

            NSLog(@"写入错误");

        }

        for (long i =0; i <_mutArr.count; i ++) {

            Student *stu =_mutArr[i];

            NSString *row = [NSStringstringWithFormat:@"%@,%@\n",stu.name,stu.num];

            constuint8_t *rowString = (constuint8_t *)[row cStringUsingEncoding:NSUTF8StringEncoding];

            NSInteger rowLength = [rowlengthOfBytesUsingEncoding:NSUTF8StringEncoding];

            result = [output write:rowStringmaxLength:rowLength];

            if (result <=0) {

                NSLog(@"无法写入内容");

            }

        }

        [output close];

    }

}



- (void)formatDates

{

    _mutArr = [NSMutableArrayarray];

    for (long i =0; i <40; i ++) {

        Student *stu = [[Studentalloc]init];

        stu.name = [NSStringstringWithFormat:@"Name啦啦啦==%ld",i];

        stu.num = [NSStringstringWithFormat:@"%ld",i*10];

        [_mutArraddObject:stu];

    }

    

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值