使用javascript链接并阅读chrome中的csv内容

时间:2018-04-14 17:59:15

标签: javascript html json excel-vba csv

我有一个csv(file.csv)文件,大部分都是使用excel打开的,我想让它充当html文件的数据源。我想使用vanilla javascript来播放数据。

我想要的最终结果如下:

我希望html文件本身就像一个成品。我不希望用户(通常是我)必须任何事情来获取数据或类似内容。

我考虑过一些事情:

选项1:

Ajax不是一个选项,因为cors政策不会允许它。这两个文件都存在于桌面上,这是他们必须留下的地方。

选项2:

使用fileReader的html表单或拖放功能不是选项。我已经可以做到这一点,结果不是我想要的。

选项3:

我没有将文件保存为file.csv,而是将其保存为file.xlsm(启用宏的工作簿),并在excel-VBA中编写子程序,以便在工作簿关闭时运行,这将重写html文件,用新数据更新它。这样就没有真正的联系;数据基本上会被硬编码到html文件中,并且只要对.xlsm文件进行更改就会被覆盖。

选项4:

我可以使用脚本标记链接到csv文件,如下所示:

private void firebaseAuthWithGoogle(GoogleSignInAccount account) {
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
mAuth.signInWithCredential(credential)
        .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if (task.isSuccessful()) {
                    // Sign in success, update UI with the signed-in user's information
                    Log.d("TAG", "signInWithCredential:success");
                    FirebaseUser user = mAuth.getCurrentUser();
                    String userID = mAuth.getCurrentUser().getUid();
                    String userName = mAuth.getCurrentUser().getDisplayName();
                    String userEmail = mAuth.getCurrentUser().getEmail();
                    DatabaseReference current_user_db = FirebaseDatabase.getInstance().getReference().child("Users");
                    Map newPost = new HashMap();
                    newPost.put("userName", userName);
                    newPost.put("userEmail", userEmail);
                    current_user_db.updateChildren(newPost); // This is the important line
                } else {
                    // If sign in fails, display a message to the user.
                    Log.w("TAG", "signInWithCredential:failure", task.getException());
                    Toast.makeText(SignUpActivity.this, "Authentication failed.",
                            Toast.LENGTH_LONG).show();
                    // updateUI(null);
                }
                // ...
            }
        });

我可以在源代码中看到该文件的内容,但我不知道如何将其删除。

选项5:

我还没有尝试过使用excel-VBA获取我的csv文件并吐出一个json文件。我可以像选项4一样链接到它,我会知道如何访问数据。

0 个答案:

没有答案