Giter Site home page Giter Site logo

No way to insert a row about excel HOT 11 CLOSED

justkawal avatar justkawal commented on August 11, 2024
No way to insert a row

from excel.

Comments (11)

nidhinmahesh avatar nidhinmahesh commented on August 11, 2024 1

I think this may help:

use:
eachRow(index,row) { List<String> dataList = [index.toString(), row['area']]; sheetObject.insertRowIterables(dataList, index+1);}

call this to populate data in loop:

maps.asMap().forEach((index,row) => eachRow(index,row));

from excel.

JmyW avatar JmyW commented on August 11, 2024 1

Thanks a lot.
Regarding insertRowIterables, I thought I insert a data in row-0, that will shift 0 to 1. I insert again a data to row-0, that will shift 1 to 2, 0 to 1. Isn't it? Thus, you called it "insert", not "update" nor "overwrite". Do I misunderstand?

from excel.

JmyW avatar JmyW commented on August 11, 2024

Thanks, I tried your way with map conversion but same. It's however added extra several null if use insertRowIterables.

from excel.

justkawal avatar justkawal commented on August 11, 2024

It's great package, thanks for contribution.
Herein I would like report an issue there is no way to insert a row. Both insertRow and insertRowIterables are failed.

  1. insertRow will cause the sheetObject crash, everything behind the index will be gone.
  2. insertRowIterables will overwrite the index's row. And on the row, the length is double with same length of "null".

Could you please check it? Or if you need a sample code for reproducing issue, I can make it. Please let me know.

Please provide a code to reproduce the issue.

from excel.

justkawal avatar justkawal commented on August 11, 2024

It's great package, thanks for contribution.
Herein I would like report an issue there is no way to insert a row. Both insertRow and insertRowIterables are failed.

  1. insertRow will cause the sheetObject crash, everything behind the index will be gone.
  2. insertRowIterables will overwrite the index's row. And on the row, the length is double with same length of "null".

Could you please check it? Or if you need a sample code for reproducing issue, I can make it. Please let me know.

I have tested the code,
It seems to be working good to me.

I would love to get the code for which u are getting any issue, So that I know that which corner cases I might have missed.
If you would not prefer disclosing it here, then you can mail me on [email protected]

from excel.

JmyW avatar JmyW commented on August 11, 2024

@justkawal Thanks for support. Please refer the code below:
The code I insert a list with 5 data. But look at the log, it's 5 data + 5 null. And I pressed 3 times, that should be supposedly accumulated three rows but not.

[*** Source code as below ***]

import 'package:flutter/material.dart';
import 'package:excel/excel.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Excel excel;
  Sheet sheetObject;

  @override
  void initState() {
    super.initState();
    excel = Excel.createExcel();
    sheetObject = excel["sheet1"];
  }

  void _incrementCounter() {
    print("Press Button");
    sheetObject.insertRowIterables(['2020-09-25','A','B','C','D'], 0);

    for (var row in sheetObject.rows) {
      print("length:${row.length} => $row");
    }
  }

  @override
  Widget build(BuildContext context) {
     return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        child: Icon(Icons.add),
      ),
    );
  }
}

[*** Printed Result as below ***]
Restarted application in 1,241ms.
I/flutter (16419): Press Button
I/flutter (16419): length:10 => [2020-09-25, A, B, C, D, null, null, null, null, null]
I/flutter (16419): Press Button
I/flutter (16419): length:10 => [2020-09-25, A, B, C, D, null, null, null, null, null]
I/flutter (16419): Press Button
I/flutter (16419): length:10 => [2020-09-25, A, B, C, D, null, null, null, null, null]

from excel.

justkawal avatar justkawal commented on August 11, 2024

Hey bro,
You are inserting the iterables onto the same row again and again
As you are passing a 0 as rowIndex in sheetObject.insertRowIterables(['2020-09-25','A','B','C','D'], 0);

  void _incrementCounter() {
    print("Press Button");
    sheetObject.insertRowIterables(['2020-09-25','A','B','C','D'], 0);

    for (var row in sheetObject.rows) {
      print("length:${row.length} => $row");
    }
  }

If you want to append the rows one after the another, there is a method named as appendRow

  void _incrementCounter() {
    print("Press Button");
    sheetObject.appendRow(['2020-09-25', 'A', 'B', 'C', 'D']);

    for (var row in sheetObject.rows) {
      print("length:${row.length} => $row");
    }
  }

I hope your issue is resolved now !!

Long Live Open Source
~Kawal

from excel.

justkawal avatar justkawal commented on August 11, 2024

I thinks there is one issue with null thing it is doubled everytime

I will check on it and will provide an update in a day or two.

from excel.

JmyW avatar JmyW commented on August 11, 2024

Hi @justkawal thanks for fixing the issue. Could you teach me how to adopt your fixes in pubspec.yaml file?

from excel.

justkawal avatar justkawal commented on August 11, 2024

By tomorrow, I'll be releasing new version with more features and bugs resolved.

from excel.

JmyW avatar JmyW commented on August 11, 2024

@justkawal Thank you!
I checked the Flutter pub.dev, but there is still 1.1.5. May I know when you will publish to Flutter pub.dev package?

from excel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.