W

로컬 텍스트 엑셀 파일 읽기/쓰기

· 16년 전 · 5835

익스플로우의 보안에 허용만 가능하면 자바스크립트 상에서도 읽기/쓰기가 가능하다.

 

우선 text파일 읽고 쓰는 예제이다.(C:\\book1.txt를 읽고 씀)

 

=====================================================================================================================

<html>
<head>
<title>file save/load</title>

 

<script type="text/javascript">

    var fso=new ActiveXObject("Scripting.FileSystemObject");
    var filename="C:\\book1.txt";
    function savefile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,2,true);
        f.Write(myarea.innerHTML);
        f.Close();
    }
   
    function loadfile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,1);
        r=f.ReadAll();
        f.Close();
        myarea.innerHTML=r;
    }
   
   
    //function window.onload() {
    //    loadfile(filename);
    //}
</script>


</head>
<body>
 <table>
  <tr>
   <td>
    <div id=myarea contenteditable=true style="width:320;height:240;border:solid 2 inset;overflow:scroll;background-color:silver;"></div>
    <br><input type=button value=load onclick=loadfile()><input type=button value=save onclick=savefile()>
   </td>
  </tr>
 </table>
</form>
</body>
</html>

 

======================================Excel 파일 열고 쓰기 =================================================

- 쓰기 -

<script type="text/javascript">

// Declare the variables
var Excel, Book;

// Create the Excel application object.
Excel = new ActiveXObject("Excel.Application");

// Make Excel visible.
Excel.Visible = true;

// Create a new work book.
Book = Excel.Workbooks.Add()

// Place some text in the first cell of the sheet.
Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";

// Save the sheet.
Book.SaveAs("C:\\book1.xls");

// Close Excel with the Quit method on the Application object.
Excel.Application.Quit();
</script>

 

- 열기 -

function StartExcel() {
var oExcel;

var oWBook;
oExcel = new ActiveXObject("Excel.Application");

oExcel.Visible = true;

oExcel.workbooks.open("C:/test.xls");

oExcel.Quit();

oExcel = null;
}

 

간단한 파일 읽기의 경우 상당히 유용할 수 있겠다..

 
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
15년 전 조회 2,332
15년 전 조회 1,135
15년 전 조회 1,616
15년 전 조회 1,591
15년 전 조회 3,380
15년 전 조회 3,727
15년 전 조회 2,414
15년 전 조회 1,869
15년 전 조회 2,492
15년 전 조회 1,976
15년 전 조회 1,597
15년 전 조회 4,288
15년 전 조회 1,939
15년 전 조회 2,021
15년 전 조회 3,281
15년 전 조회 1,986
15년 전 조회 4,694
15년 전 조회 2,877
15년 전 조회 3,683
15년 전 조회 2,283
15년 전 조회 2,525
15년 전 조회 1,826
15년 전 조회 4,891
16년 전 조회 4,497
16년 전 조회 4,293
16년 전 조회 5,720
16년 전 조회 3,940
16년 전 조회 2,292
16년 전 조회 2,264
16년 전 조회 2,411
16년 전 조회 2,108
16년 전 조회 4,539
16년 전 조회 3,437
16년 전 조회 2,600
16년 전 조회 2,196
16년 전 조회 2,398
16년 전 조회 2,901
16년 전 조회 1,992
16년 전 조회 2,908
16년 전 조회 2,240
16년 전 조회 2,361
16년 전 조회 1,987
16년 전 조회 2,700
16년 전 조회 2,011
16년 전 조회 2,439
16년 전 조회 2,620
16년 전 조회 1,695
16년 전 조회 1,747
16년 전 조회 2,417
16년 전 조회 5,836
16년 전 조회 2,145
16년 전 조회 2,672
16년 전 조회 2,853
16년 전 조회 2,008
16년 전 조회 1,802
16년 전 조회 2,716
16년 전 조회 5,441
16년 전 조회 2,706
16년 전 조회 3,361
16년 전 조회 2,229
16년 전 조회 4,107
16년 전 조회 4,912
16년 전 조회 3,557
16년 전 조회 2,812
16년 전 조회 2,930
16년 전 조회 3,142
16년 전 조회 2,657
16년 전 조회 6,007
16년 전 조회 3,834
16년 전 조회 1,831
16년 전 조회 2,163
16년 전 조회 5,532
16년 전 조회 2,782
16년 전 조회 3,856
16년 전 조회 3,136
16년 전 조회 2,032
16년 전 조회 5,849
16년 전 조회 2,951
16년 전 조회 6,443
16년 전 조회 2,417
16년 전 조회 4,468
16년 전 조회 3,474
16년 전 조회 2,671
16년 전 조회 2,696
16년 전 조회 4,821
16년 전 조회 3,756
16년 전 조회 3,279
16년 전 조회 3,434
16년 전 조회 2,551
16년 전 조회 2,217
16년 전 조회 2,143
16년 전 조회 1,851
16년 전 조회 2,135
16년 전 조회 2,344
16년 전 조회 2,049
16년 전 조회 5,300
16년 전 조회 4,301
16년 전 조회 2,240
16년 전 조회 1,990
16년 전 조회 2,739